Mosaicism

No attempts yetTime limit1sMemory limit128 MB

Problem

Molecular biologists study the genomes (that is, the sequences of genes) of organisms in order to draw conclusions about the evolution of species and the workings of cells and tissues. They compare the structure and function of genes and identify genes that are very similar to one another, called homologous genes.

While examining viruses that attack bacteria (called bacteriophages, or simply phages), they noticed a striking phenomenon. If the gene sequences of several phages are written one below another and homologous genes are painted with the same color, a peculiar mosaic appears:

To describe this phenomenon they defined a measure called the coefficient of mosaicism. It is defined for one phage only in comparison with the others, and it equals the total number of points awarded as follows. Consider the ii-th phage. For every two of its genes AA and BB, and for every two distinct phages jj and kk (with jij \ne i and kik \ne i) such that:

  • gene AA has a homologous gene in phage jj but has no homologous gene in phage kk,
  • gene BB has a homologous gene in phage kk but has no homologous gene in phage jj,

the ii-th phage receives 11 point. Each quadruple (A,B,j,k)(A, B, j, k) is counted exactly once: the quadruples (A,B,j,k)(A, B, j, k) and (B,A,k,j)(B, A, k, j) describe the same situation.

For example, in the mosaic above phage 33 has coefficient 22: its blue gene has a homolog in phage 11 but not in phage 22, while its orange gene has a homolog in phage 22 but not in phage 11 (and a symmetric pair holds for the brown and orange genes). Phage 11 has coefficient 66: it scores once each for the gene pairs red-blue and red-brown, and twice each for yellow-blue and yellow-brown.

Computing the coefficients by hand is quite hard, so write a program that reads the descriptions of homologous genes across a set of phages and computes the coefficient of mosaicism for every phage.

Input

The first line contains one integer nn (3n3003 \le n \le 300), the number of phages.

Each of the next nn lines describes one phage. The ii-th such line begins with an integer lil_i (1li3001 \le l_i \le 300), the number of genes in phage ii, followed by lil_i integers ai1,ai2,,ailia_{i1}, a_{i2}, \dots, a_{il_i} (1aij1000001 \le a_{ij} \le 100000) that list its genes in order. Consecutive numbers are separated by single spaces.

Two genes are homologous if and only if they are written as the same number. No number appears twice within a single phage (a phage never contains two mutually homologous genes).

Output

Print nn lines. The ii-th line contains a single integer: the coefficient of mosaicism of the ii-th phage.