#include<bits/stdc++.h>
using namespace std;#defineintlonglongconstint mod =998244353, P =131;constint inf=0x3f3f3f3f3f3f3f3f;constint N =3e5+10, M =100+10;
bool st[11];int mp[11][11];int n,ans;int lu[11000];int cnt=0;voiddfs(int x,int fa){//cout<<x<<endl;int cc=0;for(int i=1; i<=n; i++){if(!st[i])
cc=-1;}if(x==0&&cc==0){
ans++;return;}for(int i=0; i<=n; i++){int u=i;if(mp[x][i]==0||st[i]||i==x)continue;
st[i]=true;
lu[cnt++]=i;dfs(u,x);
st[u]=false;
cnt--;}}signedmain(){int t;
cin>>t;while(t--){
ans=0;
cin>>n;memset(mp,0,sizeof mp);for(int i=1; i<=n; i++){int m;
cin>>m;for(int j=1; j<=m; j++){int x;
cin>>x;
mp[i][x]=1;
mp[x][i]=1;}}dfs(0,-1);
cout<<ans<<endl;}return0;}
#include<bits/stdc++.h>
using namespace std;typedef pair<int,int> PII;constint N=111,M=N*N;int n,m,t;int d[N][N];voidfloyd(){for(int k =1; k <= n; k++)for(int i =1; i <= n; i++)for(int j =1; j <= n; j++)
d[i][j]=min(d[i][j], d[i][k]+ d[k][j]);}voidad(){
cin>>n>>m;memset(d,0,sizeof d);for(int i =1; i <= n; i++)for(int j =1; j <= n; j++)if(i != j)d[i][j]=99999999;for(int i=0; i<m; i++){int x,y,z;scanf("%d%d%d",&x,&y,&z);
d[x][y]=min(d[x][y],z);
d[y][x]=min(d[y][x],z);}floyd();
cin>>t;while(t--){int x,y;scanf("%d%d",&x,&y);if(d[x][y]>99999999/2)puts("-1");else cout<<d[x][y]<<endl;}}signedmain(){int t;
cin>>t;while(t--)ad();}
#include<stdio.h>intmain(){int n=1;//n个数int arr[101];while(scanf("%d",&n)!=EOF){for(int x =0; x < n; x++){scanf("%d",&arr[x]);//n个数据存于数组}for(int i =1; i < n; i++)//直接插入排序{int j;int temp = arr[i];for(j = i -1; j >=0&& arr[j]>temp; j--){
arr[j +1]= arr[j];}
arr[j +1]= temp;//第一趟插入到指定位置,结束第一趟for(int k =0; k<n; k++)//每完成一趟排序就打印{if(k ==0)printf("%d", arr[k]);elseprintf(" %d", arr[k]);}printf("\n");}}return0;}
#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>#include<stdlib.h>#include<string.h>#definemax105typedefstruct{int data;}SqListN;typedefstruct{
SqListN r[max];int length;}SqList;voidHeap_Adjust(SqList* H,int s,int m){
SqListN rc = H->r[s];for(int i =2* s; i <= m; i *=2){if(i < m && H->r[i].data < H->r[i +1].data){
i++;}if(!(rc.data < H->r[i].data)){break;}
H->r[s]= H->r[i];
s = i;}
H->r[s]= rc;}voidHeap_Swap(SqListN* a, SqListN* b){int data = a->data;
a->data = b->data;
b->data = data;}voidHeap_Sort(SqList* H){for(int i = H->length /2; i >0; i--){Heap_Adjust(H, i, H->length);}for(int i = H->length; i >1; i--){Heap_Swap(&(H->r[1]),&(H->r[i]));Heap_Adjust(H,1, i -1);for(int i =1; i < H->length; i++){printf("%d ", H->r[i]);}printf("%d\n", H->r[H->length].data);}}intmain(){
SqList H;while(~scanf("%d",&H.length)){for(int i =1; i <= H.length; i++){scanf("%d",&H.r[i]);}Heap_Sort(&H);}return0;}