The feeling sucks
After putting in hours of studying, it can be pretty devastating to find out that you failed a test. The first thing to do is to not take it personally. A test will not determine your entire life course and it does not define your intelligence. It will not accurately measure your stance as a student. In fact, you could just have a bad teacher or other extra circumstances. For example, you may have a job, and therefore less time to study. You may have to take care of your siblings or clean the house. Just know that everyone fails a test once in a while, and the best thing to do is just learn from it. Learn what what mistakes you made the first time in order to correct those mistakes the second time.
How to remotivate yourself
Failing a test can be really unmotivating. It can cause you to panic and it can make you feel as if everything is spirraling over. The first thing to do is to calm down. Remind yourself that everything will be okay in the end. The second thing to do is to talk to other people. Chances are there's people who did and didn't do well on the exam. Ask the people who did well for tips and ask those who didn't do well to form a study group. Remember that the fact you're tying at all is a big step. Even if you don't score 100%, getting a way better score than a fail is a testament to how much you tried.
-Write down the material in order to increase chances of memorization
-Study for many minutes then take a break, and repeat.
-Take a practice test
-Teach the material to someone, it helps with thorough understanding
-Create or join a study group
-Watch online videos
-Create a study schedule to stay on task and organized
-Create short term goals.