Codeforces Round 792 (Div. 1 + Div. 2)
C
Column Swapping
Codeforces
1400
原题
← BD →
翻译中…

You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \le j \le m$ the following holds: $a_{i,j} \ge a_{i, j-1}$.

翻译中…

You have to to do the following operation exactly once: choose two columns with indexes $i$ and $j$ (not necessarily different), $1 \le i, j \le m$, and swap them.

翻译中…

You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the number of rows and columns respectively.

翻译中…

Each of the next $n$ rows contains $m$ integers, $j$-th element of $i$-th row is $a_{i,j}$ ($1 \le a_{i,j} \le 10^9$) — the number written in the $j$-th cell of the $i$-th row.

翻译中…

It's guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

If after the swap it is impossible to get a good grid, output $-1$.

翻译中…

In the other case output $2$ integers — the indices of the columns that should be swapped to get a good grid.

翻译中…

If there are multiple solutions, print any.

翻译中…

Note

翻译中…

In the first test case the grid is initially good, so we can, for example, swap the first column with itself.

翻译中…

In the second test case it is impossible to make the grid good.

翻译中…

In the third test case it is needed to swap the first and the second column, then the grid becomes good.

翻译中…

样例

Input #1
5
2 3
1 2 3
1 1 1
2 2
4 1
2 3
2 2
2 1
1 1
2 3
6 2 1
5 4 3
2 1
1
2
Output #1
1 1
-1
1 2
1 3
1 1
InputCopy OutputCopy
题目信息
题号
1684C
时间限制
1 s
内存限制
256 MB
标签
暴力
构造
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。