Share your code or submission link
you should give the question link , your solution link with your question. helps other to answer easily.
You may get negative answers. -5\%3 computes as -2, but what you want is 1.
i solved it with a simple calculation using queue
if you want you can refer to my code-https://www.codechef.com/viewsolution/35616238