#include using namespace std; #define il inline #define rg register #define int long long il int read() { int re=0,k=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')k=-1;ch=getchar();} while(ch<='9'&&ch>='0'){re=re*10+ch-48;ch=getchar();} return re*k; } il void write(int x) { if(x<0)return putchar('-'),write(-x),void(); if(x<10)return putchar(x+48),void(); return write(x/10),write(x%10),void(); } int n,a[100005],sum,ans,fa[20005],len[20005];bool vis[20005]; vector s[105][11]; /* int find(int x) { if(x==fa[x])return x; return fa[x]=find(fa[x]); } int merge(int u,int v) { u=find(u);v=find(v); fa[u]=v; return v; }*/ signed main() { int T=read(); while(T--) { memset(vis,0,sizeof(vis)); vis[1]=1; for(int i=1;i<=100;i++) for(int j=1;j<=10;j++) s[i][j].clear(); int n=read(); for(int i=1;i<=n;i++) { len[i]=read(); for(int j=1;j<=len[i];j++) { int t=read(); int p=read(); s[t][p].push_back(i); } } for(int i=1;i<=100;i++) { for(int j=1;j<=10;j++) { bool p=0; for(int k=0;k