That sounds so difficult and upsetting! I’m so proud of you for trying to push through.
Remind yourself this distress is temporary, since it began it will end eventually on its own. Get yourself in a calmer state by self-soothing (ideas: jump in the shower for a few minutes to reset your nervous system and turn it to cold or hot - test the water to make sure it isn’t too hot or cold first, wrap yourself in comfy clothes, lay down, breathe).
Then cope ahead (it’s a DBT skill). Sit with the possibility of failing, and imagine yourself coping with that. For example, if you fail, you can explore retaking the test (never hurts to explain to your teacher and ask), retake the class, take a different class, speak to your teacher, get accommodations for suture tests from your school, study with a friend/tutor for the next test, etc. Then after imagining yourself coping well with the worst case scenario, imagine the best case scenario, you going to take the test and calming yourself down the beat you can, completing the test, passing the test - getting a D, C, B, or A. Once you do this, self soothe again (ideas: turn on lofi music, put a wax warmer on, spray some soothing perfume, have an easy snack and drink a glass of cold water).
Try studying again, and see if you feel any differently. Take a break after an hour or two. Repeat, self soothing, studying, break. Call it quits when you start to feel too tired or exhausted. Tomorrow before the test, imagine yourself feeling calmer before taking it, and imagine yourself passing.
Remind yourself that everyone fails tests throughout their life, and everyone is able to cope with it better than they know. I am not trying to gloat, but just stating a fact with this point -> I have failed a lot of tests and some classes, and I still have my masters and hold two wonderful per diem jobs. When I failed, I cried and grieved, and I kept trying although it felt like the end of the world. You are smarter and stronger than you know 🙌 I believe in you and will be proud of you no matter the outcome!