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;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline int getint() {
  int ret = 0;
  bool ok = 0, neg = 0;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + ret + ret + c - '0', ok = 1;
    else if (ok)
      return neg ? -ret : ret;
    else if (c == '-')
      neg = 1;
  }
}
int m, d, n;
long long base[10][10], a[10];
map<long long, int> hs;
int main() {
  m = getint();
  d = getint();
  for (int zz = 0; zz < m; zz++) {
    int c = getint();
    for (int j = 0; j < d; j++)
      for (int k = 0; k < d; k++) base[j][k] = 0;
    for (int z = 0; z < c; z++) {
      for (int k = 0; k < d; k++) {
        a[k] = getint();
        if (a[k] < 0) a[k] += mod;
      }
      for (int j = 0; j < d; j++) {
        if (!a[j]) continue;
        if (base[j][j]) {
          long long w = mod - a[j];
          for (int k = j; k < d; k++) a[k] = (a[k] + w * base[j][k]) % mod;
        } else {
          long long w = powmod(a[j], mod - 2);
          for (int k = j; k < d; k++) base[j][k] = a[k] * w % mod;
          break;
        }
      }
    }
    for (int j = 0; j < d; j++)
      if (base[j][j]) {
        for (int i = 0; i < j; i++)
          if (base[i][j]) {
            long long w = mod - base[i][j];
            for (int k = j; k < d; k++) {
              base[i][k] = (base[i][k] + w * base[j][k]) % mod;
            }
          }
      }
    long long p = 0;
    for (int j = 0; j < d; j++) {
      for (int k = 0; k < d; k++) p = p * 13331 + base[j][k];
    }
    if (!hs.count(p)) hs[p] = ++n;
    printf("%d ", hs[p]);
  }
}
