It is now 125 years later, but humanity is still on the run from a humanoid-cyborg race determined to destroy it. Or perhaps we are getting some stories mixed up here... In any case, the fleet is now smaller. However, in a recent upgrade, all the navigation systems have been outfitted with higher-dimensional, linear-algebraic jump processors.

Now, in order to make a jump, a ship's captain needs to specify a subspace of the d-dimensional space in which the events are taking place. She does so by providing a generating set of vectors for that subspace.

Princess Heidi has received such a set from the captain of each of m ships. Again, she would like to group up those ships whose hyperspace jump subspaces are equal. To do so, she wants to assign a group number between 1 and m to each of the ships, so that two ships have the same group number if and only if their corresponding subspaces are equal (even though they might be given using different sets of vectors).

Help Heidi!

Input

The first line of the input contains two space-separated integers m and d (2 ≤ m ≤ 30 000, 1 ≤ d ≤ 5) – the number of ships and the dimension of the full underlying vector space, respectively. Next, the m subspaces are described, one after another. The i-th subspace, which corresponds to the i-th ship, is described as follows:

The first line contains one integer ki (1 ≤ ki ≤ d). Then ki lines follow, the j-th of them describing the j-th vector sent by the i-th ship. Each of the j lines consists of d space-separated integers aj, j = 1, ..., d, that describe the vector <image>; it holds that |aj| ≤ 250. The i-th subspace is the linear span of these ki vectors.

Output

Output m space-separated integers g1, ..., gm, where <image> denotes the group number assigned to the i-th ship. That is, for any 1 ≤ i < j ≤ m, the following should hold: gi = gj if and only if the i-th and the j-th subspaces are equal. In addition, the sequence (g1, g2, ..., gm) should be lexicographically minimal among all sequences with that property.

Example

Input

8 2
1
5 0
1
0 1
1
0 1
2
0 6
0 1
2
0 1
1 0
2
-5 -5
4 3
2
1 1
0 1
2
1 0
1 0


Output

1 2 2 2 3 3 3 1 

Note

In the sample testcase, the first and the last subspace are equal, subspaces 2 to 4 are equal, and subspaces 5 to 7 are equal.

Recall that two subspaces, one given as the span of vectors <image> and another given as the span of vectors <image>, are equal if each vector vi can be written as a linear combination of vectors w1, ..., wk (that is, there exist coefficients <image> such that vi = α1w1 + ... + αkwk) and, similarly, each vector wi can be written as a linear combination of vectors v1, ..., vn.

Recall that a sequence (g1, g2, ..., gm) is lexicographically smaller than a sequence (h1, h2, ..., hm) if there exists an index i, 1 ≤ i ≤ m, such that gi < hi and gj = hj for all j < i.
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool get_int(T &x) {
  char t = getchar();
  bool neg = false;
  x = 0;
  for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
    ;
  if (t == '-') neg = true, t = getchar();
  if (t == EOF) return false;
  for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
  if (neg) x = -x;
  return true;
}
template <typename T>
void print_int(T x) {
  if (x < 0) putchar('-'), x = -x;
  short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
const int inf = 0x3f3f3f3f;
const long long Linf = 1ll << 61;
const double pi = acos(-1.0);
const int mod = 998244353;
int power(int x, int y) {
  int ret = 1;
  do {
    if (y & 1) ret = 1ll * ret * x % mod;
    x = 1ll * x * x % mod;
  } while (y >>= 1);
  return ret;
}
int m, d, v[30111][25];
bool cmp(int x, int y) {
  for (int i = 0; i < 25; i++)
    if (v[x][i] != v[y][i]) return v[x][i] < v[y][i];
  return false;
}
int n, a[5][5], ord[30111], ans[30111];
void construct() {
  memset(a, 0, sizeof(a));
  get_int(n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < d; j++) {
      get_int(a[i][j]);
      if (a[i][j] < 0) a[i][j] += mod;
    }
  for (int i = 0, cur = 0; cur < d; cur++) {
    int piv = -1;
    for (int j = i; j < n && piv == -1; j++)
      if (a[j][cur]) piv = j;
    if (piv == -1)
      continue;
    else {
      for (int j = 0; j < d; j++) swap(a[i][j], a[piv][j]);
      int rv = power(a[i][cur], mod - 2);
      for (int j = cur; j < d; j++) a[i][j] = 1ll * a[i][j] * rv % mod;
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        rv = a[j][cur];
        for (int k = 0; k < d; k++)
          a[j][k] = (a[j][k] - 1ll * a[i][k] * rv % mod + mod) % mod;
      }
      i++;
    }
  }
}
int tmp[30111];
int main() {
  (get_int(m) && get_int(d));
  for (int i = 1; i <= m; i++) {
    construct();
    for (int j = 0; j < d; j++)
      for (int k = 0; k < d; k++) v[i][j * d + k] = a[j][k];
    ord[i] = i;
  }
  sort(ord + 1, ord + m + 1, cmp);
  ans[ord[1]] = 1;
  for (int i = 2; i <= m; i++) {
    bool ok = 1;
    for (int j = 0; j < 25; j++) ok &= (v[ord[i]][j] == v[ord[i - 1]][j]);
    ans[ord[i]] = ans[ord[i - 1]] + (ok ^ 1);
  }
  int cur = 0;
  for (int i = 1; i <= m; i++) {
    if (!tmp[ans[i]]) tmp[ans[i]] = ++cur;
    printf("%d ", tmp[ans[i]]);
  }
  return 0;
}
