Losing focus in an exam, how does it affect my goal - grad school So I'll explain my self briefly, I've just finished my first semester in my undergrad program and my goal is to move on to masters in the US in Stanford or near that area.

So obviously grades are very important and here's the problem, I'm putting the hours in throughout all the semester (easily 10 hours a day, sometimes longer) and I don't have  issues with understanding nor with executing what was learned but come the day of the exam and I do TERRIBLY and I can't explain why, I don't know whether it's because of stress  or something else and I feel lost as everyone I score a B instead of an A I feel like my grad school goal is only getting further away from me.

I'd appreciate any tips or ideas with how to deal with this.
I'm currently retaking all the tests to improve my grades but it's exhausting because the material is not the problem...

In case it matters, I'm talking about computer science.

if the title is inappropriate please let me know how to change it 

Thank you

Edit: my topic is different from the one  mwhombat linked to because where I live you don't get to pick your courses I can't focus on project based courses some have then but most don't so I HAVE to get better at test taking
I would try to find some of your class mates, that are performing very well on the tests and ask them for some advice. Regarding what sources they are specifically studying, how they decide what material to prep for the exam and what not to etc.

If you don't know anyone yet that is performing very well, this is a great opportunity to make some new friends. Taking tests is really an art form all of its own, and I'm sure those in your class that score highly will have some insights they could share with you about how to sit and prepare for a test well. 

Also ask your faculty if they have old papers, you could practice with, you might also ask a member of the teaching staff to perhaps do a mock invigilation for you, with an old paper, and give you feedback about how you did, and where it fell short. Practice makes perfect. 

Also isolate the reason you are not doing well in the tests. Is it because you simply do not know the answers? Or are you running out of time? Or are you not reading the question properly under exam conditions? Once you know this you will be in a better position to develop a strategy to improve in the key areas that are impacting your scores.