DZY Loves Sorting

Time Limit: 6000ms
Memory Limit: 262144KB
This problem will be judged on HDU. Original ID: 5649
64-bit integer IO format: %I64d      Java class name: Main

Description

DZY has a sequence $a[1..n]$. It is a permutation of integers $1 \sim n$.

Now he wants to perform two types of operations:

$0 \,\,l \,\,r$: Sort $a[l..r]$ in increasing order.

$1\,\, l \,\,r$: Sort $a[l..r]$ in decreasing order.

After doing all the operations, he will tell you a position $k$, and ask you the value of $a[k]$.

Input

First line contains $t$, denoting the number of testcases.

$t$ testcases follow. For each testcase:

First line contains $n,m$. $m$ is the number of operations.

Second line contains $n$ space-separated integers $a[1],a[2],\cdots,a[n]$, the initial sequence. We ensure that it is a permutation of $1\sim n$.

Then $m$ lines follow. In each line there are three integers $opt,l,r$ to indicate an operation.

Last line contains $k$.

($1\le t \le 50,1\le n,m \le 100000,1\le k \le n, 1\le l\le r\le n, opt \in \{0,1\}$. Sum of $n$ in all testcases does not exceed $150000$. Sum of $m$ in all testcases does not exceed $150000$)

Output

For each testcase, output one line - the value of $a[k]$ after performing all $m$ operations.

Sample Input

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

Sample Output

5

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .