Deal with academic failure as an undergraduate
Allocate time specifically to prepare for your tests
This might seem like a waste of time, since you would rather spend it studying the course material more deeply. However, this is a trade-off you should be willing to make in pursuit of your long-term goal of entering into research. If 100% of your studying time is currently spent on learning the course material deeply, you may need to reduce that to 75–80%, and spend the rest of the time doing test preparation. I understand that test preparation can be extremely boring and feel completely pointless. But, as you've noticed yourself, you need to score a minimum amount of marks to stay afloat in the system. There is no need to judge yourself by your course marks, though; feel free to think of it as just an arbitrary number that you need to display in order to apply to graduate programs.
Furthermore, to the best of my knowledge, a few failing grades will not disqualify you from applying to the graduate programs of any university. I believe you have options to take the failed courses again, or at least their final exams, so make use of that. If you plan to apply to graduate programs in India, in particular, as long as your overall grades lie above the cutoff and you perform well in the interviews, you should be fine.
Finally, your attitude towards your education is commendable, but at some point the effort involved in going through the system may end up not being worth it. Several talented classmates of mine found this to be true for themselves, and chose to take other paths. You will need to choose your path, too, and possibly very soon. But try your best to fulfil at least the bare minimum requirements before deciding that this system is not for you.