405970: GYM102192 J Taotao Picks Apples

Memory Limit:128 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Taotao Picks Applestime limit per test2 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard output

There is an apple tree in front of Taotao's house. When autumn comes, n apples on the tree ripen, and Taotao will go to pick these apples.

When Taotao picks apples, Taotao scans these apples from the first one to the last one. If the current apple is the first apple, or it is strictly higher than the previously picked one, then Taotao will pick this apple; otherwise, he will not pick.

Given the heights of these apples h1, h2, ..., hn, you are required to answer some independent queries. Each query is two integers p, q, which asks the number of apples Taotao would pick, if the height of the p-th apple were q (instead of hp). Can you answer all these queries?

Input

The first line of input is a single line of integer T (1 ≤ T ≤ 10), the number of test cases.

Each test case begins with a line of two integers n, m (1 ≤ n, m ≤ 105), denoting the number of apples and the number of queries. It is then followed by a single line of n integers h1, h2, ..., hn (1 ≤ hi ≤ 109), denoting the heights of the apples. The next m lines give the queries. Each of these m lines contains two integers p (1 ≤ p ≤ n) and q (1 ≤ q ≤ 109), as described in the problem statement.

Output

For each query, display the answer in a single line.

ExampleInput
1
5 3
1 2 3 4 4
1 5
5 5
2 3
Output
1
5
3
Note

For the first query, the heights of the apples were 5, 2, 3, 4, 4, so Taotao would only pick the first apple.

For the second query, the heights of the apples were 1, 2, 3, 4, 5, so Taotao would pick all these five apples.

For the third query, the heights of the apples were 1, 3, 3, 4, 4, so Taotao would pick the first, the second and the fourth apples.

加入题单

算法标签: