ROBOTS: Need help

I am solving ROBOTS problem.
My logic is as below:

  1. In first pass, get the final pos of all instructions and store them in a dictionary.
  2. Now, get the L, R of each query. It boils down to two cases.
    a) if L == 1, then just we need to return finalpos[R]
    b) Else, translate and rotate origin to finalpos[L-1] and find co-ordinates w.r.t to new origin.

However, am getting WA. could you please help me in solving this?

https://www.codechef.com/viewsolution/27951666

Thanks in advance!!

This might help: https://discuss.codechef.com/t/robots-cookoff-easy-solution/44791