cho.sh
Notes
Loading...

Printer Queue

Time limit

2s

Memory limit

128 MB

Problem

A printer normally prints documents in the order their print requests arrive. When several documents are waiting, they form a queue, and the document that entered first is processed first.

This printer processes documents by the following rules.

  1. Take the document at the front of the queue and check its priority.
  2. If any remaining document has a higher priority, do not print the current document; move it to the back of the queue.
  3. If no remaining document has a higher priority, print the current document.

For instance, if four documents A B C D have priorities 2 1 4 3 in that order, they are printed in the order C, D, A, B.

Given the number of documents in the queue and each document's priority, determine the print order of one specific document. In the situation above, C is printed 1st and A is printed 3rd.

Input

The first line contains the number of test cases. Each test case consists of two lines.

The first line of a test case contains the number of documents N and the current position M of the document of interest. The leftmost document has position 0, and 0 ≤ M < N.

The second line contains the priorities of the N documents from left to right in the current queue. Each priority is an integer from 1 to 9, and multiple documents may have the same priority.

  • 1 ≤ N ≤ 100

Output

For each test case, print one line containing the 1-based order in which the document of interest is printed.