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!
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 *k*<sub class="lower-index">*i*</sub> (1 ≤ *k*<sub class="lower-index">*i*</sub> ≤ *d*). Then *k*<sub class="lower-index">*i*</sub> 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 *a*<sub class="lower-index">*j*</sub>, *j* = 1, ..., *d*, that describe the vector <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ab929a3e14032f5003e6f023f92be72813548b37.png" style="max-width: 100.0%;max-height: 100.0%;"/>; it holds that |*a*<sub class="lower-index">*j*</sub>| ≤ 250. The *i*-th subspace is the linear span of these *k*<sub class="lower-index">*i*</sub> vectors.
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 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8dc56705315ce4b334dd46dbc9c8c51fffb0036.png" style="max-width: 100.0%;max-height: 100.0%;"/> and another given as the span of vectors <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99fd3b5233ff3b6f4989df43e2f60edb184bee11.png" style="max-width: 100.0%;max-height: 100.0%;"/>, are equal if each vector *v*<sub class="lower-index">*i*</sub> can be written as a linear combination of vectors *w*<sub class="lower-index">1</sub>, ..., *w*<sub class="lower-index">*k*</sub> (that is, there exist coefficients <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ae69b90a53c26d24b0b4a40a6970f6d5903cd568.png" style="max-width: 100.0%;max-height: 100.0%;"/> such that *v*<sub class="lower-index">*i*</sub> = α<sub class="lower-index">1</sub>*w*<sub class="lower-index">1</sub> + ... + α<sub class="lower-index">*k*</sub>*w*<sub class="lower-index">*k*</sub>) and, similarly, each vector *w*<sub class="lower-index">*i*</sub> can be written as a linear combination of vectors *v*<sub class="lower-index">1</sub>, ..., *v*<sub class="lower-index">*n*</sub>.

Recall that a sequence (*g*<sub class="lower-index">1</sub>, *g*<sub class="lower-index">2</sub>, ..., *g*<sub class="lower-index">*m*</sub>) is lexicographically smaller than a sequence (*h*<sub class="lower-index">1</sub>, *h*<sub class="lower-index">2</sub>, ..., *h*<sub class="lower-index">*m*</sub>) if there exists an index *i*, 1 ≤ *i* ≤ *m*, such that *g*<sub class="lower-index">*i*</sub> &lt; *h*<sub class="lower-index">*i*</sub> and *g*<sub class="lower-index">*j*</sub> = *h*<sub class="lower-index">*j*</sub> for all *j* &lt; *i*.
from fractions import *
m,d = [int(x) for x in input().split(' ')]
v = {}
cur = 0
for i in range(m):
	k = int(input())
	a = []
	for j in range(k):
		g = [Fraction(int(x)) for x in input().split(' ')]
		a.append(g)
	
	n = len(a)
	m = len(a[0])
	c = 0
	r = 0
	while c < m and r < n:
		j = r
		for i in range(r+1, n):
			if abs(a[i][c]) > abs(a[j][c]):
				j = i
		if a[j][c] == 0:
			c = c + 1
			continue
		
		for i in range(m):
			a[j][i], a[r][i] = a[r][i], a[j][i]
		s = 1 / a[r][c]
		
		for j in range(m):
			a[r][j] *= s
		for i in range(n):
			if i != r:
				t = a[i][c]
				for j in range(m):
					a[i][j] -= t * a[r][j]
		r = r + 1
		c = c + 1
	qq = []
	for x in a[:r]:
		qq += x
	b = tuple(qq)
	if b not in v:
		cur = cur + 1
		v[b] = cur
	print(v[b], end=' ')
