Input: arr[] = {1, 3, 1, 3}, query[] = {3, 1}
Output: 1 3 3 1
Explanation: In 1st iteration, send first occurrence of query[0] to the end, i.e, send first occurrence of 3 to the end.
Hence, the array becomes arr[] = {1, 1, 3, 3}.
In 2nd iteration, send first occurrence of query[1] to the end.
Hence, array arr[] = {1, 3, 3, 1} which is the required array.
Input: arr[] = {1, 2, 3, 4, 5}, query[] = {4, 3}
Output: 1 2 5 4 3