#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 30000;
const int MAXDIM = 5;
struct S {
  long long a[MAXDIM][MAXDIM];
  int nrow, ncol;
  void norm() {
    int r = 0, c = 0;
    while (r < nrow && c < ncol) {
      {
        int rr = r;
        for (int rrr = (r + 1); rrr < (nrow); ++rrr)
          if (abs(a[rrr][c]) > abs(a[rr][c])) rr = rrr;
        if (a[rr][c] == 0) {
          ++c;
          continue;
        }
        for (int cc = (0); cc < (ncol); ++cc) swap(a[r][cc], a[rr][cc]);
      }
      if (a[r][c] < 0)
        for (int cc = (0); cc < (ncol); ++cc) a[r][cc] = -a[r][cc];
      for (int rr = (r + 1); rr < (nrow); ++rr)
        if (a[rr][c] != 0) {
          long long g = gcd(a[r][c], abs(a[rr][c]));
          for (int cc = (0); cc < (ncol); ++cc) a[rr][cc] *= a[r][c] / g;
          long long t = a[rr][c] / a[r][c];
          for (int cc = (0); cc < (ncol); ++cc) a[rr][cc] -= t * a[r][cc];
        }
      ++r, ++c;
    }
    nrow = r;
    for (--r; r >= 0; --r) {
      c = 0;
      while (a[r][c] == 0) ++c;
      {
        long long g = a[r][c];
        for (int cc = (c + 1); cc < (ncol); ++cc) g = gcd(g, abs(a[r][cc]));
        for (int cc = (0); cc < (ncol); ++cc) a[r][cc] /= g;
      }
      for (int rr = (0); rr < (r); ++rr)
        if (a[rr][c] != 0) {
          long long g = gcd(a[r][c], abs(a[rr][c]));
          for (int cc = (0); cc < (ncol); ++cc) a[rr][cc] *= a[r][c] / g;
          long long t = a[rr][c] / a[r][c];
          for (int cc = (0); cc < (ncol); ++cc) a[rr][cc] -= t * a[r][cc];
        }
    }
  }
};
bool operator<(const S &p, const S &q) {
  if (p.ncol != q.ncol) return p.ncol < q.ncol;
  if (p.nrow != q.nrow) return p.nrow < q.nrow;
  for (int i = (0); i < (p.nrow); ++i)
    for (int j = (0); j < (p.ncol); ++j)
      if (p.a[i][j] != q.a[i][j]) return p.a[i][j] < q.a[i][j];
  return false;
}
int n, ncol;
S s[MAXN];
map<S, int> mp;
int id[MAXN];
void run() {
  scanf("%d%d", &n, &ncol);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &s[i].nrow);
    s[i].ncol = ncol;
    for (int j = (0); j < (s[i].nrow); ++j)
      for (int k = (0); k < (s[i].ncol); ++k) scanf("%lld", &s[i].a[j][k]);
  }
  for (int i = (0); i < (n); ++i) s[i].norm();
  mp.clear();
  for (int i = (0); i < (n); ++i) {
    if (!mp.count(s[i])) {
      int nid = ((int)(mp).size());
      mp[s[i]] = nid;
    }
    id[i] = mp[s[i]];
  }
  for (int i = (0); i < (n); ++i) {
    if (i != 0) printf(" ");
    printf("%d", id[i] + 1);
  }
  puts("");
}
int main() {
  run();
  return 0;
}
