#D746. Reverse

    ID: 616 Type: Default 1000ms 268MiB

Reverse

Reverse

Write a program which reads a sequence of integers A=a0,a1,...,an1A = \\{a_0, a_1, ..., a_{n-1}\\} and reverse specified elements by a list of the following operation:

  • reverse(b,eb, e): reverse the order of ab,ab+1,...,ae1a_b, a_{b+1}, ..., a_{e-1}

Constraints

  • 1n1,0001 \leq n \leq 1,000
  • 1,000,000,000ai1,000,000,000-1,000,000,000 \leq a_i \leq 1,000,000,000
  • 1q1,0001 \leq q \leq 1,000
  • 0b<en0 \leq b < e \leq n

Input

The input is given in the following format.

nn a0  a1  ...,  an1a_0 \; a_1 \; ...,\; a_{n-1} qq b1  e1b_1 \; e_1 b2  e2b_2 \; e_2 : bq  bqb_{q} \; b_{q}

In the first line, nn (the number of elements in AA) is given. In the second line, aia_i (each element in AA) are given. In the third line, the number of queries qq is given and each query is given by two integers bi  eib_i \; e_i in the following qq lines.

Output

Print all elements of AA in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.

Example

Input

8 1 2 3 4 5 6 7 8 2 1 6 3 8

Output

1 6 5 8 7 2 3 4

inputFormat

Input

The input is given in the following format.

nn a0  a1  ...,  an1a_0 \; a_1 \; ...,\; a_{n-1} qq b1  e1b_1 \; e_1 b2  e2b_2 \; e_2 : bq  bqb_{q} \; b_{q}

In the first line, nn (the number of elements in AA) is given. In the second line, aia_i (each element in AA) are given. In the third line, the number of queries qq is given and each query is given by two integers bi  eib_i \; e_i in the following qq lines.

outputFormat

Output

Print all elements of AA in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.

Example

Input

8 1 2 3 4 5 6 7 8 2 1 6 3 8

Output

1 6 5 8 7 2 3 4

样例

8
1 2 3 4 5 6 7 8
2
1 6
3 8
1 6 5 8 7 2 3 4