#include <bits/stdc++.h>
using namespace std;
struct TrieNode {
struct TrieNode* ch[11];
TrieNode() {
for (int i = 0; i < 11; i++) {
ch[i] = nullptr;
}
}
~TrieNode() {
for (int i = 0; i < 11; i++) {
if (ch[i] != nullptr) {
delete ch[i];
}
}
}
};
TrieNode* root;
void add(TrieNode* node, const vector<int>& a) {
for(int i = 0; i < a.size(); i++) {
int id = a[i];
if (node->ch[id] == nullptr) {
node->ch[id] = new TrieNode;
}
node = node->ch[id];
}
}
int check(TrieNode* node, const vector<int>& a) {
int cnt = 0;
for (int i = 0; i < a.size(); i++) {
int id = a[i];
if (node->ch[id] != nullptr) {
node = node->ch[id];
++cnt;
} else {
return cnt;
}
}
return cnt;
}
vector<int> div(vector<int>& a) {
vector<int> res(a.size(), 0);
for (int i = 0; i < a.size(); i++) {
int id = a[i] - 1;
res[id] = i+1;
}
return res;
}
void solve() {
int n, m;
scanf("%d%d", &n, &m);
root = new TrieNode;
vector<vector<int>> perms(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &perms[i][j]);
}
vector<int> c = div(perms[i]);
add(root, c);
}
int ans = 0;
for (int i = 0; i < n; i++) {
int t = check(root, perms[i]);
printf(i == 0 ? "%d":" %d", t);
}
printf("\n");
delete root;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
1358B - Maria Breaks the Self-isolation | 828A - Restaurant Tables |
1735A - Working Week | 1735D - Meta-set |
1735B - Tea with Tangerines | 1735C - Phase Shift |
1321C - Remove Adjacent | 281B - Nearest Fraction |
1043A - Elections | 1598C - Delete Two Elements |
1400C - Binary String Reconstruction | 1734D - Slime Escape |
1499A - Domino on Windowsill | 991A - If at first you don't succeed |
1196C - Robot Breakout | 373A - Collecting Beats is Fun |
965A - Paper Airplanes | 863E - Turn Off The TV |
630E - A rectangle | 1104A - Splitting into digits |
19C - Deletion of Repeats | 1550B - Maximum Cost Deletion |
1693A - Directional Increase | 735D - Taxes |
989A - A Blend of Springtime | 339C - Xenia and Weights |
608A - Saitama Destroys Hotel | 1342C - Yet Another Counting Problem |
548A - Mike and Fax | 109A - Lucky Sum of Digits |