We have N balls(numbered from 1 to N) and we have 2 types of queries:
1-put ball x in front of ball y
2-print the ith ball's number
initial state: 1 2 3 4
query 1 : 1 3 1 --> 3 1 2 4
query 2 : 1 4 3 --> 4 3 1 2
query 3 : 2 2 --> 3
query 4 : 2 4 --> 2
How to perform these queries efficiently ?







