I have back and neck pain for 2-3 days. I sit in same position for many hours studying. Pain is not going away. Should I take medicine or exercise?

Muscle spasm. Could result from poor posture or as you mention, being in the same position por long periods of time. You should try getting up and stretching at regular intervals during your study time, gentle massage and heat may also help relieve your discomfort. If your pain persists or worsens you should seek medical attention. Good luck!