#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int d, cnt, B[7][7], a[7];
unordered_map<long long, int> mp;
int gmp(long long x) {
  if (mp.find(x) == mp.end()) mp[x] = ++cnt;
  return mp[x];
}
void fmain(int ID) {
  scanf("%d%d", &n, &d);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d", &k);
    memset(B, 0, sizeof B);
    for (int(z) = 1; (z) <= (int)(k); (z)++) {
      for (int(zz) = 0; (zz) < (int)(d); (zz)++) {
        scanf("%d", a + zz);
        if (a[zz] < 0) a[zz] += 1000000007;
      }
      for (int(j) = 0; (j) < (int)(d); (j)++) {
        if (a[j] == 0) continue;
        if (B[j][j] == 0) {
          int w = fastPow(a[j], 1000000007 - 2);
          for (int t = j; t < d; t++) {
            B[j][t] = (long long)a[t] * w % 1000000007;
          }
          break;
        } else {
          int w = 1000000007 - a[j];
          for (int t = j; t < d; t++) {
            addmod(a[t], (long long)w * B[j][t] % 1000000007);
          }
        }
      }
    }
    for (int(j) = 0; (j) < (int)(d); (j)++)
      if (B[j][j]) {
        for (int z = 0; z < j; z++)
          if (B[z][j]) {
            int w = 1000000007 - B[z][j];
            for (int x = j; x < d; x++) {
              addmod(B[z][x], (long long)w * B[j][x] % 1000000007);
            }
          }
      }
    long long tmp = 0;
    for (int(x) = 0; (x) < (int)(d); (x)++)
      for (int(y) = 0; (y) < (int)(d); (y)++) tmp = tmp * 2017 + B[x][y];
    printf("%d ", gmp(tmp));
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
