Masturbation is killing my school performance

So yeah, title says it all. Currently on a Pre-med course and so far I got good midterm grades. But I've gotten to a point where masturbation is my stimulus to keep satisfy myself to keep going studying, and I'm really sick and tired of it being a double edged sword:

just now I'm bummed out tired from school and travel ( 2 hour travel) and yet I need to prepare for a unit exam tomorrow morning at 7 am. First thing I wanna do was to catch sum z's before studying but then yeah, the impulse comes along, gotta scroll to find the best stuff that be stimulating, then boom blue light kicks away the need to sleep, and now I'm stuck forcing myself to study yet nothing coming in because i'm sleepy yet can't fall asleep at the same time.

I'm aware that I should be seeing other people or doing stuff away from it - I deliberately chose a gym months ago thats miles away from home to up my time away from my room and interact with people outside cause being and feeling alone is my trigger to masturbation. It was starting to work yet the pre-med course's study load really removed my agency to continue it, heck the gym was a really the reason why I had that discipline to study and burn yhe midnight oil helping me deposit good grades, but the course took this agency away due to the load being too much (frequent quizes that really need to be studied). As of the moment I'd accept my fate that I'll be doing bad for tomorrow's unit exam in exchange for proper z's but i'm fearful that my failure tomorrow might contribute into me getting into that addicting loop, like bruh I don't want to go back. This had been a reoccuring dilemma recently and tis only now that I'd raise the white flag against struggling to study cause i'm bummed out drained for the semester and I got finals right around the corner around 5 days from now.