Our warehouses usually have lots of boxes of shoes on their shelves. These boxes are also frequently moved within shelves, storage racks, or warehouses. Deciding where each box should be stored is complicated, as there are many variables to account for (e.g., the time it takes to retrieve an item, or the item's proximity to other products). For the purposes of this challenge, we've reduced this complex problem into something a bit simpler.

Let's say we have one shelf that holds a single line of boxes. In other words, there are positions on a long shelf, and each position can hold a single box.

There are boxes on the shelf, and each box has an ID number associated with it. Business needs often require this ordering be changed, so the warehouse employees receive queries to rearrange the boxes throughout the day. Each query is in the form l r, and the query is executed by moving all boxes in the inclusive range to the head (front) of the shelf.

As warehouse developers, we should be able to identify the final position of any particular box. Given queries and the initial ordering of all boxes, can you find the final ordering of the box IDs on the shelf?

Input Format

The first line contains an integer, , denoting the number of boxes we can store on our shelf.
The second line contains space-separated integers in the inclusive range from to describing the respective initial position for each box on the shelf. The third line contains a single integer, , denoting the number of queries described in the Problem Statement above.
Each of the subsequent lines describes a query in the form of two space-separated integers, and , defining the respective left and right boundaries for the interval of boxes that needs to be moved to the head (front) of the shelf.

Constraints

  • , and all IDs are unique

Output Format

Print space-separated integers denoting the ID number of each box with respect to its final position on the shelf.

Sample Input

6
1 2 3 4 5 6
3
4 5
3 4
2 3

Sample Output

2 4 1 5 3 6

Explanation

The shelf initially looks like this: . We execute our queries in the following order:

  1. Move the and items on the shelf to the front, so our shelf looks like this: .
  2. Move the and items on the shelf to the front, so our shelf looks like this: .
  3. Move the and items on the shelf to the front, so our shelf looks like this: .

We then print this final ordering of ID numbers as our answer.

Line: 1 Col: 1
  1. Challenge Walkthrough
    Let's walk through this sample challenge and explore the features of the code editor.1 of 6
  2. Review the problem statement
    Each challenge has a problem statement that includes sample inputs and outputs. Some challenges include additional information to help you out.2 of 6
  3. Choose a language
    Select the language you wish to use to solve this challenge.3 of 6
  4. Enter your code
    Code your solution in our custom editor or code in your own environment and upload your solution as a file.4 of 6
  5. Test your code
    You can compile your code and test it for errors and accuracy before submitting.5 of 6
  6. Submit to see results
    When you're ready, submit your solution! Remember, you can go back and refine your code anytime.6 of 6
  1. Check your score