How to cope with failing qualify exams?
From someone who's been there - I started in a PhD program in mathematics, received only a "Masters pass" on my written qualifiers the first time around, retook a year later to the same result. Left the program with a masters, since we only had two tries. Fast forward 2 years and I'm admitted into a different PhD program in mathematics. This school has oral qualifiers. First attempt at that and I literally break down and cry and ask to just stop and try later. Reprepared, and nailed it the next time. 

I just finished my PhD in mathematics. I took longer than most due to qualifier issues at one school, changing to another, changing areas of mathematics, and dealing with increased imposter syndrome due to the experiences at school 1. Long story short, it's not a competition with other students. Don't compare yourself to others. You were admitted to the program and you can do it. Study hard, ask the professors for advice and follow it. If it doesn't happen, it's OK. You can still achieve a PhD, just perhaps at different university and at a different time. I am proof of that. Best of luck.