Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/qidiruv-saralangan-jadval

Search in a sorted table

Easy 1000 ms 128 MB 28%
Share

A table with $n$ rows and $m$ columns is given. Read row by row (the first row from left to right, then the second row and so on), its numbers are strictly increasing. Each of $q$ queries gives an integer $x$: in which row and which column of the table is it? If it is not in the table, print $-1$.

A table increasing row by row: the cell with the searched number and the search path to it are highlighted

Input

The first line contains three positive integers: $n$, $m$ and $q$.
Each of the next $n$ lines contains $m$ integers — the table.
Each of the next $q$ lines contains one integer $x$.

Output

For each query on a separate line: the row and column numbers, or $-1$.

Note

$1 \le n \cdot m \le 10^{5}$
$1 \le q \le 10^{5}$
the numbers of the table and $x$ do not exceed $10^{9}$ in absolute value

Examples

Input #1
3 4 3
1 3 5 7
10 11 16 20
23 30 34 60
3
16
13
Output #1
1 2
2 3
-1
Input #2
1 1 2
5
5
-5
Output #2
1 1
-1

Sign in to submit a solution

Signing up is free and takes a minute.