#include <bits/stdc++.h>
using namespace std;
const int p = 998244353, q = (int)1e9 + 123;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  a.first += b.first;
  a.second += b.second;
  if (a.first >= p) {
    a.first -= p;
  }
  if (a.second >= q) {
    a.second -= q;
  }
  return a;
}
pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {
  a.first -= b.first;
  a.second -= b.second;
  if (a.first < 0) {
    a.first += p;
  }
  if (a.second < 0) {
    a.second += q;
  }
  return a;
}
pair<int, int> operator*(pair<int, int> a, pair<int, int> b) {
  a.first = (long long)a.first * b.first % p;
  a.second = (long long)a.second * b.second % q;
  return a;
}
const int maxn = (int)30010;
pair<int, int> t[maxn];
pair<int, int> s[maxn];
int g[maxn];
map<pair<int, int>, int> hs;
int d;
pair<int, int> v[10][10];
void sswap(int x, int y) {
  for (int i = 0; i < d; i++) {
    swap(v[x][i], v[y][i]);
  }
}
int my_pow(int x, int y, int mod) {
  if (y == 0) {
    return 1;
  }
  if (y & 1) {
    return (long long)x * my_pow(x, y - 1, mod) % mod;
  }
  long long z = my_pow(x, y >> 1, mod);
  return z * z % mod;
}
pair<int, int> rev(pair<int, int> a) {
  if (a.first == 0 || a.second == 0) {
    throw 1;
  }
  a.first = my_pow(a.first, p - 2, p);
  a.second = my_pow(a.second, q - 2, q);
  return a;
}
pair<int, int> get_hsh(int k) {
  int pos = 0;
  for (int i = 0; i < d; i++) {
    bool fl = false;
    for (int j = pos; j < k; j++) {
      if (v[j][i] != make_pair(0, 0)) {
        sswap(j, pos);
        fl = true;
        break;
      }
    }
    if (!fl) {
      continue;
    }
    pair<int, int> g = rev(v[pos][i]);
    for (int j = 0; j < d; j++) {
      v[pos][j] = v[pos][j] * g;
    }
    for (int j = pos + 1; j < k; j++) {
      pair<int, int> cf = v[j][i];
      for (int w = 0; w < d; w++) {
        v[j][w] = v[j][w] - v[pos][w] * cf;
      }
    }
    pos++;
  }
  for (int i = k - 1; i >= 0; i--) {
    int e = -1;
    for (int j = 0; j < d; j++) {
      if (v[i][j] != make_pair(0, 0)) {
        e = j;
        break;
      }
    }
    if (e == -1) {
      continue;
    }
    if (v[i][e] != make_pair(1, 1)) {
      throw 1;
    }
    for (int j = i - 1; j >= 0; j--) {
      pair<int, int> cf = v[j][e];
      for (int w = 0; w < d; w++) {
        v[j][w] = v[j][w] - v[i][w] * cf;
      }
    }
  }
  pair<int, int> hsh = make_pair(0, 0);
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < d; j++) {
      hsh = hsh + t[i] * s[j] * v[i][j];
    }
  }
  return hsh;
}
int main() {
  t[0] = make_pair(1, 1);
  s[0] = make_pair(1, 1);
  for (int i = 0; i < maxn; i++) {
    t[i] = {rand() % p, rand() % q};
    s[i] = {rand() % p, rand() % q};
  }
  int n;
  scanf("%d %d", &n, &d);
  int num = 1;
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      for (int f = 0; f < d; f++) {
        int x;
        scanf("%d", &x);
        if (x >= 0) {
          v[j][f] = make_pair(x, x);
        } else {
          v[j][f] = make_pair(x + p, x + q);
        }
      }
    }
    pair<int, int> f = get_hsh(k);
    if (!hs.count(f)) {
      hs[f] = num++;
    }
    g[i] = hs[f];
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", g[i]);
  }
  return 0;
}
