#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 30000;
long long base[6][6], a[6];
int n, d, c;
map<unsigned long long, int> h;
long long Pow(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
long long inv(long long a) { return Pow(a, mod - 2, mod); }
void ins(long long *a) {
  for (int i = 1; i <= d; ++i)
    if (a[i])
      if (base[i][i]) {
        long long num = mod - a[i];
        for (int j = i; j <= d; ++j)
          a[j] = (a[j] + num * base[i][j] % mod) % mod;
      } else {
        long long num = inv(a[i]);
        for (int j = i; j <= d; ++j) a[j] = a[j] * num % mod;
        for (int j = 1; j <= d; ++j) base[i][j] = a[j];
        break;
      }
}
int main() {
  int T;
  scanf("%d%d", &T, &d);
  while (T--) {
    memset(base, 0, sizeof(base));
    scanf("%d", &n);
    for (int k = 1; k <= n; ++k) {
      for (int i = 1; i <= d; ++i)
        scanf("%lld", &a[i]), a[i] = (a[i] + mod) % mod;
      ins(a);
    }
    for (int i = 1; i <= d; ++i)
      if (base[i][i])
        for (int j = 1; j < i; ++j)
          if (base[j][i]) {
            long long num = mod - base[j][i];
            for (int k = 1; k <= d; ++k)
              base[j][k] = (base[j][k] + num * base[i][k] % mod) % mod;
          }
    unsigned long long num = 0;
    for (int i = 1; i <= d; ++i)
      for (int j = 1; j <= d; ++j) num = num * 233 + base[i][j];
    if (h[num] == 0) h[num] = ++c;
    printf("%d ", h[num]);
  }
  return 0;
}
