#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
const int MAX_N=1e2+5;
int main()
{
	int T; si(T);
	while(T--)
	{
		vector<set<int> >seg;
		int n; si(n);
		repi(i,1,n-1){
			set<int> s;
			int k; si(k);
			while(k--){
				int x; si(x);
				s.insert(x);
			}
			seg.pb(s);
		}
		vector<int> ans;
		repi(st,1,n){
			ans.clear();
			vector<set<int> >cur=seg;
			bool flag=true;
			for(auto &it:cur)if(it.count(st)) it.erase(st);
			ans.pb(st);
			repi(i,2,n){
				vector<int> tmp;
				for(auto &it:cur)if(it.size()==1) tmp.pb(*it.begin());
				if(tmp.size()!=1){
					flag=false;break;
				}
				ans.pb(tmp.front());
				for(auto &it:cur)if(it.count(tmp.front())) it.erase(tmp.front());
			}
			set<set<int> >s(seg.begin(),seg.end());
			if(flag){
				repi(ed,1,n-1){
					set<int> tmp;
					repd(st,ed,0){
						tmp.insert(ans[st]);
						if(s.count(tmp)){
							s.erase(tmp);break;
						}
					}
				}
				if(s.empty()) break;
			}
		}
		repi(i,0,n-1) printf("%d%c",ans[i],ce(i,n-1));
	}
	return 0;
}


#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e2+5;
int n,ans[MAX_N];
int p[MAX_N][MAX_N];
set<int> rec[MAX_N];
int main()
{
	int T; si(T);
	while(T--)
	{
		int n; si(n);
		repi(i,1,n) rec[i].clear();
		repi(i,1,n-1){
			si(p[i][0]);
			repi(j,1,p[i][0]) si(p[i][j]),rec[p[i][j]].insert(i);
		}
		repd(i,n,2){
			int cnt=0,p1=-1,p2=-1;
			repi(j,1,n)if(rec[j].size()==1){
				cnt++;
				if(p1==-1) p1=j;
				else p2=j;
			}
			if(cnt==2) ans[1]=p2,rec[p2].clear();
			ans[i]=p1;
			int tmp=*rec[p1].begin();
			repi(k,1,p[tmp][0])if(rec[p[tmp][k]].size()) rec[p[tmp][k]].erase(tmp);
		}
		repi(i,1,n) printf("%d%c",ans[i],ce(i,n));
	}
	return 0;
}


#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e2+5;
int n,ans[MAX_N];
int p[MAX_N][MAX_N],siz[MAX_N];
set<int> rec[MAX_N];
int main()
{
	int T; si(T);
	while(T--)
	{
		int n; si(n);
		repi(i,1,n) rec[i].clear();
		repi(i,1,n-1){
			si(p[i][0]);
			repi(j,1,p[i][0]) si(p[i][j]),rec[p[i][j]].insert(i);
		}
		repi(i,1,n) siz[i]=rec[i].size();
		repd(i,n,2){
			int cnt=0,p1=-1,p2=-1;
			repi(j,1,n)if(rec[j].size()==1){
				cnt++;
				if(p1==-1) p1=j;
				else p2=j;
			}
			if(cnt==2){
				if(siz[p2]>siz[p1]) swap(p1,p2);
				ans[1]=p2,rec[p2].clear();
			}
			ans[i]=p1;
			int tmp=*rec[p1].begin();
			repi(k,1,p[tmp][0])if(rec[p[tmp][k]].size()) rec[p[tmp][k]].erase(tmp);
		}
		repi(i,1,n) printf("%d%c",ans[i],ce(i,n));
	}
	return 0;
}


#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e2+5;
int n,ans[MAX_N];
int p[MAX_N][MAX_N],siz[MAX_N];
set<int> rec[MAX_N];
bool flag[MAX_N];
int main()
{
	int T; si(T);
	while(T--)
	{
		int n; si(n);
		ms(flag);
		repi(i,1,n) rec[i].clear();
		repi(i,1,n-1){
			si(p[i][0]);
			repi(j,1,p[i][0]) si(p[i][j]),rec[p[i][j]].insert(i);
		}
		repi(i,1,n) siz[i]=rec[i].size();
		int front=0;
		repd(i,n,2){
			int p1=-1,p2=-1;
			repi(j,1,n)if(rec[j].size()==1){
				if(p1==-1) p1=j;
				else p2=j;
			}
			if(p1==-1) break;
			if(p2!=-1){
				if(siz[p2]>siz[p1]) swap(p1,p2);
				ans[++front]=p2,flag[p2]=true;
				int tmp=*rec[p2].begin();
				repi(k,1,p[tmp][0]) rec[p[tmp][k]].erase(tmp);
			}
			ans[i]=p1,flag[p1]=true;
			if(!rec[p1].size()) continue;
			int tmp=*rec[p1].begin();
			repi(k,1,p[tmp][0]) rec[p[tmp][k]].erase(tmp);
		}
		repi(i,1,n)if(!flag[i]){
			ans[++front]=i;
			break;
		}
		repi(i,1,n) printf("%d%c",ans[i],ce(i,n));
	}
	return 0;
}


#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e2+5;
int n,ans[MAX_N];
int p[MAX_N][MAX_N];
set<int> rec[MAX_N];
bool flag[MAX_N];
int main()
{
	int T; si(T);
	while(T--)
	{
		int n; si(n);
		ms(flag);
		repi(i,1,n) rec[i].clear();
		repi(i,1,n-1){
			si(p[i][0]);
			repi(j,1,p[i][0]) si(p[i][j]),rec[p[i][j]].insert(i);
		}
		int front=0;
		repd(i,n,2){
			int p1=-1,p2=-1;
			repi(j,1,n)if(rec[j].size()==1){
				if(p1==-1) p1=j;
				else p2=j;
			}
			if(p1==-1) break;
			if(p2!=-1){
				ans[++front]=p2,flag[p2]=true;
				int tmp=*rec[p2].begin();
				repi(k,1,p[tmp][0]) rec[p[tmp][k]].erase(tmp);
			}
			ans[i]=p1,flag[p1]=true;
			if(!rec[p1].size()) continue;
			int tmp=*rec[p1].begin();
			repi(k,1,p[tmp][0]) rec[p[tmp][k]].erase(tmp);
		}
		repi(i,1,n)if(!flag[i]){
			ans[++front]=i;
			break;
		}
		repi(i,1,n) printf("%d%c",ans[i],ce(i,n));
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define RG register int
#define LL long long

template<typename elemType>
inline void Read(elemType &T){
    elemType X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    T=(w?-X:X);
}

int N,a[205][205],Pos[205],Ans[205];
int T;

bool Judge(){
	int b;
	for(RG i=2;i<=N;++i){
		for(RG j=1;j<=N-1;++j){
			int Len=a[j][0],x=-1;
			for(RG k=1;k<=a[j][0];++k){
				b=a[j][k];
				if(!Pos[b]) x=b;
				else if(Pos[b]>=i-a[j][0]+1) --Len;
			}
			if(Len==1 && x!=-1){Ans[i]=x,Pos[x]=i;break;}
		}
		if(Ans[i]==0) return false;
	}
	return true;
}

int main(){
	Read(T);
	while(T--){
        Read(N);
		for(RG i=1;i<=N-1;++i){
            Read(a[i][0]);
			for(RG j=1;j<=a[i][0];++j)
                Read(a[i][j]);
		}
		for(RG i=1;i<=N;++i){
			fill(Ans+1,Ans+N+1,0);
            fill(Pos+1,Pos+N+1,0);
            Ans[1]=i;
			Pos[i]=1;
			if(Judge()) break;
		}
		for(RG i=1;i<N;++i)
            printf("%d ",Ans[i]);
		printf("%d\n",Ans[N]);
	}
	return 0;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 0
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
void Main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n - 1);
  vector<vector<int>> b;
  vector<int> cnt(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int k;
    cin >> k;
    a[i].resize(k);
    for (auto &x: a[i]) cin >> x, cnt[x]++;
  }
  vector<int> ans(n + 1);
  auto check = [](int x, vector<int> b) {
    auto it = lower_bound(b.begin(), b.end(), x);
    if (it == b.end() || *it != x) return 0;
    return 1;
  };
  auto checks = [&](int x, vector<vector<int>> bs) {
    for (auto &b: bs) {
      if (!check(x, b)) return 0;
    }
    return 1;
  };
  for (int r = n; r >= 2; r--) {
    int id = -1, rx;
    for (int i = 0; i < a.size(); i++) {
      for (auto &x: a[i]) {
        if (cnt[x] == 1 && checks(x, b)) {
          id = i;
          rx = x;
          goto go;
        }
      }
    }
    go:
    debug(r, b);
    for (auto &x: a[id]) cnt[x]--;
    b.push_back(a[id]);
    a.erase(a.begin() + id);
    ans[r] = rx;
    for (auto &v: b) {
      for (auto it = v.begin(); it != v.end(); it++) {
        if (*it == rx) {
          v.erase(it);
          break;
        }
      }
    }
    auto bb = b;
    b.resize(0);
    for (auto &x: bb) if (x.size()) b.push_back(x);
  }
  cout << n * (n + 1) / 2 - accumulate(ans.begin() + 2, ans.end(), 0);
  for (int i = 2; i <= n; i++) cout << " " << ans[i];
  cout << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 0
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
void Main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n - 1);
  vector<vector<int>> b;
  vector<int> cnt(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int k;
    cin >> k;
    a[i].resize(k);
    for (auto &x: a[i]) cin >> x, cnt[x]++;
  }
  vector<int> ans(n + 1);
  auto check = [](vector<int> a, vector<int> b) {
    for (auto &x: a) {
      auto it = lower_bound(b.begin(), b.end(), x);
      if (it == b.end() || *it != x) return 0;
    }
    return 1;
  };
  auto checks = [&](vector<int> a, vector<vector<int>> bs) {
    for (auto &b: bs) {
      int x;
      if (a.size() < b.size()) x = check(a, b);
      else x = check(b, a);
      if (!x) return 0;
    }
    return 1;
  };
  for (int r = n; r >= 2; r--) {
    int id = -1, rx;
    for (int i = 0; i < a.size(); i++) {
      for (auto &x: a[i]) {
        if (cnt[x] == 1 && checks(a[i], b)) {
          id = i;
          rx = x;
          goto go;
        }
      }
    }
    go:
    for (auto &x: a[id]) cnt[x]--;
    b.push_back(a[id]);
    a.erase(a.begin() + id);
    ans[r] = rx;
    for (auto &v: b) {
      for (auto it = v.begin(); it != v.end(); it++) {
        if (*it == rx) {
          v.erase(it);
          break;
        }
      }
    }
    auto bb = b;
    b.resize(0);
    for (auto &x: bb) if (x.size()) b.push_back(x);
  }
  cout << n * (n + 1) / 2 - accumulate(ans.begin() + 2, ans.end(), 0);
  for (int i = 2; i <= n; i++) cout << " " << ans[i];
  cout << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 0
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
void Main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n - 1);
  vector<vector<int>> b;
  vector<int> cnt(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int k;
    cin >> k;
    a[i].resize(k);
    for (auto &x: a[i]) cin >> x, cnt[x]++;
  }
  vector<int> ans(n + 1);
  auto check = [](int x, vector<int> b) {
    auto it = lower_bound(b.begin(), b.end(), x);
    if (it == b.end() || *it != x) return 0;
    return 1;
  };
  auto checks = [&](int x, vector<vector<int>> bs) {
    for (auto &b: bs) {
      if (!check(x, b)) return 0;
    }
    return 1;
  };
  auto aa = a;
  auto bb = b;
  auto cc = cnt;
  for (int go = 0; go < 2; go++) {
    bool done = 0;
    a = aa;
    b = bb;
    cnt = cc;
    for (int r = n; r >= 2; r--) {
      int id = -1, rx;
      for (int i = 0; i < a.size(); i++) {
        for (auto &x: a[i]) {
          if (cnt[x] == 1 && checks(x, b)) {
            if (!done && go == 1) {
              done = 1;
              continue;
            }
            id = i;
            rx = x;
            goto go;
          }
        }
      }
      go:
      if (id == -1) goto go2;
      for (auto &x: a[id]) cnt[x]--;
      b.push_back(a[id]);
      a.erase(a.begin() + id);
      ans[r] = rx;
      for (auto &v: b) {
        for (auto it = v.begin(); it != v.end(); it++) {
          if (*it == rx) {
            v.erase(it);
            break;
          }
        }
      }
      auto bb = b;
      b.resize(0);
      for (auto &x: bb) if (x.size()) b.push_back(x);
    }
    break;
    go2:;
  }
  cout << n * (n + 1) / 2 - accumulate(ans.begin() + 2, ans.end(), 0);
  for (int i = 2; i <= n; i++) cout << " " << ans[i];
  cout << endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

set<int> seg1[205];
set<int> seg2[205];
bool b[205];
int ans[205];
vector<int> vec[205];
vector<int> rev(205);
vector<int> temp;

int main()
{
	optimize();
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		for( int i = 0; i <= n; ++i ) {
			seg1[i].clear();
			seg2[i].clear();
			vec[i].clear();
			b[i] = 0;
		}
		for( int i = 0; i < n-1; ++i ) {
			int k;
			cin >> k;
			for( int j = 0; j < k; ++j ) {
				int x;
				cin >> x;
				seg1[i].insert(x);
				vec[x].PB(i);
			}
		}
		for( int i = 1; i <= n; ++i ) {
			for( int j = 0; j < n-1; ++j ) {
				seg2[j].clear();
				seg2[j] = seg1[j];
				b[j] = 0;
			}
			int cur = i;
			bool ok = 0;
			ans[1] = cur;
			//if( t == 4 ) for( int j = 0; j < n-1; ++j ) if( !b[j] ) dbg(j, seg2[j]);
			//if( t == 4 ) cout << endl;
			for( int j = 2; j <= n; ++j ) {
				int cnt = 0;
				int idx = 0;
				for( auto x : vec[cur] ) {
					if( b[x] ) continue;
					if( seg2[x].size() == 2 ) {
						idx = x;
						++cnt;
					}
				}
				//if(t == 1) dbg(vec[cur], seg2[0], seg1[0], cur);
				if( cnt != 1 ) {
					ok = 1;
					break;
				}
				for( auto x : vec[cur] ) {
					if( b[x] ) continue;
					seg2[x].erase( cur );
				}
				b[idx] = 1;
				//if( t == 4 ) for( int j = 0; j < n-1; ++j ) if(!b[j]) dbg(j, seg2[j]);
				//if( t == 4 ) cout << endl;
				b[idx] = 1;
				cur = *seg2[idx].begin();
				ans[j] = cur;
			}
			for( int j = 1; j <= n; ++j ) rev[ans[j]] = j;
			for( int j = 0; j < n-1; ++j ) {
				temp.clear();
				for( auto x : seg1[j] ) temp.PB(rev[x]);
				sort( temp.begin(), temp.end() );
				for( int k = 1; k < (int)temp.size(); ++k ) {
					//dbg(k);
					if( temp[k] != temp[k-1]+1 ) {
						ok = 1;
						break;
					}
				}
				if(ok) break;
			}
			if(!ok) break;
		}
		for( int i = 1; i <= n; ++i ) cout << ans[i] << " "; cout << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

set<int> seg1[205];
set<int> seg2[205];
bool b[205];
int ans[205];
vector<int> vec[205];

int main()
{
	optimize();
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		for( int i = 0; i <= n; ++i ) {
			seg1[i].clear();
			seg2[i].clear();
			vec[i].clear();
			b[i] = 0;
		}
		for( int i = 0; i < n-1; ++i ) {
			int k;
			cin >> k;
			for( int j = 0; j < k; ++j ) {
				int x;
				cin >> x;
				seg1[i].insert(x);
				vec[x].PB(i);
			}
		}
		for( int i = 1; i <= n; ++i ) {
			for( int j = 0; j < n-1; ++j ) {
				seg2[j].clear();
				seg2[j] = seg1[j];
				b[j] = 0;
			}
			int cur = i;
			bool ok = 0;
			ans[1] = cur;
			for( int j = 2; j <= n; ++j ) {
				int cnt = 0;
				int idx = 0;
				for( auto x : vec[cur] ) {
					if( b[x] ) continue;
					if( seg2[x].size() == 2 ) {
						idx = x;
						++cnt;
					}
				}
				//if(t == 1) dbg(vec[cur], seg2[0], seg1[0], cur);
				if( cnt != 1 ) {
					ok = 1;
					break;
				}
				for( auto x : vec[cur] ) {
					if( b[x] ) continue;
					seg2[x].erase( cur );
				}
				b[idx] = 1;
				cur = *seg2[idx].begin();
				ans[j] = cur;
			}
			if(!ok) break;
		}
		for( int i = 1; i <= n; ++i ) cout << ans[i] << " "; cout << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	program();
}

//===================//
//   begin program   //
//===================//

const int MX = 210;
int t, n, k[MX], a[MX][MX];
set<int> inA[MX];
vi ans;
set<set<int>> sts;

void findAns(int i) {
    ans.pb(i);
    int u = *inA[i].begin();
    RE(j,k[u]) inA[a[u][j]].erase(u);
    RE(j,k[u]) {
        if(a[u][j] != i && inA[a[u][j]].size() == 0) {
            ans.pb(a[u][j]);
            return;
        }
        if(inA[a[u][j]].size() == 1) {
            findAns(a[u][j]);
            return;
        }
    }
}
bool findAns2(bool rev=0) {
    RE1(i,n) inA[i].clear();
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    ans.clear();
    if(rev) {
        REV(i,1,n+1) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    } else {
        RE1(i,n) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    }
    reverse(ans.begin(), ans.end());
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    if(inA[ans[0]].size() > inA[ans[1]].size()) swap(ans[0], ans[1]);
    REP(i,1,n) {
        bool found = 0;
        set<int> cs; cs.insert(i);
        REV(j,0,i-1) {
            if(sts.count(cs)) {
                found = 1;
                break;
            }
        }
        if(!found) return 0;
    }
    return 1;
}

void program() {
    cin>>t;
    while(t--) {
        cin>>n;
        RE(i,n-1) {
            cin>>k[i];
            RE(j,k[i]) cin>>a[i][j];
            set<int> cs;
            RE(j,k[i]) cs.insert(a[i][j]);
            sts.insert(cs);
        }
        if(!findAns2(0)) findAns2(1);
        RE(i,ans.size()) cout<<(i==0?"":" ")<<ans[i]; cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	program();
}

//===================//
//   begin program   //
//===================//

const int MX = 210;
int t, n, k[MX], a[MX][MX];
set<int> inA[MX];
vi ans;

void findAns(int i) {
    ans.pb(i);
    int u = *inA[i].begin();
    RE(j,k[u]) inA[a[u][j]].erase(u);
    RE(j,k[u]) {
        if(a[u][j] != i && inA[a[u][j]].size() == 0) {
            ans.pb(a[u][j]);
            return;
        }
        if(inA[a[u][j]].size() == 1) {
            findAns(a[u][j]);
            return;
        }
    }
}

void program() {
    cin>>t;
    while(t--) {
        cin>>n;
        RE(i,n-1) {
            cin>>k[i];
            RE(j,k[i]) cin>>a[i][j];
        }
        RE1(i,n) inA[i].clear();
        RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
        ans.clear();
        RE1(i,n) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
        reverse(ans.begin(), ans.end());
        RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
        if(inA[ans[0]].size() > inA[ans[1]].size()) swap(ans[0], ans[1]);
        RE(i,ans.size()) cout<<(i==0?"":" ")<<ans[i]; cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	program();
}

//===================//
//   begin program   //
//===================//

const int MX = 210;
int t, n, k[MX], a[MX][MX];
set<int> inA[MX];
vi ans;
set<set<int>> sts;

void findAns(int i) {
    ans.pb(i);
    int u = *inA[i].begin();
    RE(j,k[u]) inA[a[u][j]].erase(u);
    RE(j,k[u]) {
        if(a[u][j] != i && inA[a[u][j]].size() == 0) {
            ans.pb(a[u][j]);
            return;
        }
        if(inA[a[u][j]].size() == 1) {
            findAns(a[u][j]);
            return;
        }
    }
}
bool findAns2(bool rev=0) {
    RE1(i,n) inA[i].clear();
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    ans.clear();
    if(rev) {
        REV(i,1,n+1) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    } else {
        RE1(i,n) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    }
    reverse(ans.begin(), ans.end());
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    if(inA[ans[0]].size() > inA[ans[1]].size()) swap(ans[0], ans[1]);
    REP(i,1,n) {
        bool found = 0;
        set<int> cs; cs.insert(ans[i]);
        REV(j,0,i) {
            cs.insert(ans[j]);
            if(sts.count(cs)) {
                found = 1;
                break;
            }
        }
        if(!found) return 0;
    }
    return 1;
}

void program() {
    cin>>t;
    while(t--) {
        cin>>n;
        sts.clear();
        RE(i,n-1) {
            cin>>k[i];
            RE(j,k[i]) cin>>a[i][j];
            set<int> cs;
            RE(j,k[i]) cs.insert(a[i][j]);
            sts.insert(cs);
        }
        if(!findAns2(0)) findAns2(1);
        RE(i,ans.size()) cout<<(i==0?"":" ")<<ans[i]; cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	program();
}

//===================//
//   begin program   //
//===================//

const int MX = 210;
int t, n, k[MX], a[MX][MX];
set<int> inA[MX];
vi ans;

void findAns(int i) {
    ans.pb(i);
    int u = *inA[i].begin();
    RE(j,k[u]) inA[a[u][j]].erase(u);
    RE(j,k[u]) {
        if(a[u][j] != i && inA[a[u][j]].size() == 0) {
            ans.pb(a[u][j]);
            return;
        }
        if(inA[a[u][j]].size() == 1) {
            findAns(a[u][j]);
            return;
        }
    }
}

void program() {
    cin>>t;
    while(t--) {
        cin>>n;
        RE(i,n-1) {
            cin>>k[i];
            RE(j,k[i]) cin>>a[i][j];
        }
        RE1(i,n) inA[i].clear();
        RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
        ans.clear();
        RE1(i,n) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
        reverse(ans.begin(), ans.end());
        RE(i,ans.size()) cout<<(i==0?"":" ")<<ans[i]; cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	program();
}

//===================//
//   begin program   //
//===================//

const int MX = 210;
int t, n, k[MX], a[MX][MX];
set<int> inA[MX];
vi ans;
set<set<int>> sts;

void findAns(int i) {
    ans.pb(i);
    int u = *inA[i].begin();
    RE(j,k[u]) inA[a[u][j]].erase(u);
    RE(j,k[u]) {
        if(a[u][j] != i && inA[a[u][j]].size() == 0) {
            ans.pb(a[u][j]);
            return;
        }
        if(inA[a[u][j]].size() == 1) {
            findAns(a[u][j]);
            return;
        }
    }
}
bool findAns2(bool rev=0) {
    RE1(i,n) inA[i].clear();
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    ans.clear();
    if(rev) {
        REV(i,1,n+1) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    } else {
        RE1(i,n) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    }
    reverse(ans.begin(), ans.end());
    RE1(i,n) inA[i].clear();
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    if(inA[ans[0]].size() > inA[ans[1]].size()) swap(ans[0], ans[1]);
    REP(i,1,n) {
        bool found = 0;
        set<int> cs; cs.insert(ans[i]);
        REV(j,0,i) {
            cs.insert(ans[j]);
            if(sts.count(cs)) {
                found = 1;
                break;
            }
        }
        if(!found) return 0;
    }
    return 1;
}

void program() {
    cin>>t;
    while(t--) {
        cin>>n;
        sts.clear();
        RE(i,n-1) {
            cin>>k[i];
            RE(j,k[i]) cin>>a[i][j];
            set<int> cs;
            RE(j,k[i]) cs.insert(a[i][j]);
            sts.insert(cs);
        }
        if(!findAns2(0)) if(!findAns2(1)) assert(0);
        RE(i,ans.size()) cout<<(i==0?"":" ")<<ans[i]; cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	program();
}

//===================//
//   begin program   //
//===================//

const int MX = 210;
int t, n, k[MX], a[MX][MX];
set<int> inA[MX];
vi ans;
set<set<int>> sts;

bool findAns2(int BEG) {
    ans.clear();
    RE(i,n-1) inA[i].clear();
    RE(i,n-1) RE(j,k[i]) inA[i].insert(a[i][j]);
    queue<int> nxt; nxt.push(BEG);
    while(!nxt.empty()) {
        int u = nxt.front(); nxt.pop();
        ans.pb(u);
        RE(i,n-1) {
            if(inA[i].size() == 1) continue;
            inA[i].erase(u);
            if(inA[i].size() == 1) nxt.push(*inA[i].begin());
        }
    }
    if(ans.size() != n) return 0;
    REP(i,1,n) {
        bool found = 0;
        set<int> cs; cs.insert(ans[i]);
        REV(j,0,i) {
            cs.insert(ans[j]);
            if(sts.count(cs)) {
                found = 1;
                break;
            }
        }
        if(!found) return 0;
    }
    return 1;
}

void program() {
    cin>>t;
    while(t--) {
        cin>>n;
        sts.clear();
        RE(i,n-1) {
            cin>>k[i];
            RE(j,k[i]) cin>>a[i][j];
            set<int> cs;
            RE(j,k[i]) cs.insert(a[i][j]);
            sts.insert(cs);
        }
        RE1(i,n) {
            if(findAns2(i)) break;
        }
        RE(i,ans.size()) cout<<(i==0?"":" ")<<ans[i]; cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

//===================//
//  Added libraries  //
//===================//

//===================//
//end added libraries//
//===================//

void program();
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	program();
}

//===================//
//   begin program   //
//===================//

const int MX = 210;
int t, n, k[MX], a[MX][MX];
set<int> inA[MX];
vi ans;
set<set<int>> sts;

void findAns(int i) {
    ans.pb(i);
    int u = *inA[i].begin();
    RE(j,k[u]) inA[a[u][j]].erase(u);
    RE(j,k[u]) {
        if(a[u][j] != i && inA[a[u][j]].size() == 0) {
            ans.pb(a[u][j]);
            return;
        }
        if(inA[a[u][j]].size() == 1) {
            findAns(a[u][j]);
            return;
        }
    }
}
bool findAns2(bool rev=0) {
    RE1(i,n) inA[i].clear();
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    ans.clear();
    if(rev) {
        REV(i,1,n+1) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    } else {
        RE1(i,n) {
            if(inA[i].size() == 1) {
                findAns(i);
            }
        }
    }
    reverse(ans.begin(), ans.end());
    RE(i,n-1) RE(j,k[i]) inA[a[i][j]].insert(i);
    if(inA[ans[0]].size() > inA[ans[1]].size()) swap(ans[0], ans[1]);
    REP(i,1,n) {
        bool found = 0;
        set<int> cs; cs.insert(i);
        REV(j,0,i-1) {
            if(sts.count(cs)) {
                found = 1;
                break;
            }
        }
        if(!found) return 0;
    }
    return 1;
}

void program() {
    cin>>t;
    while(t--) {
        cin>>n;
        sts.clear();
        RE(i,n-1) {
            cin>>k[i];
            RE(j,k[i]) cin>>a[i][j];
            set<int> cs;
            RE(j,k[i]) cs.insert(a[i][j]);
            sts.insert(cs);
        }
        if(!findAns2(0)) findAns2(1);
        RE(i,ans.size()) cout<<(i==0?"":" ")<<ans[i]; cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define MAXN 210
#define MOD 200000007
#define inf 0x3f3f3f3f

int n;
int a[MAXN];
int v[MAXN][MAXN];
int in[MAXN];
int ans[MAXN];
int l[MAXN];

int findv(int x){

    for(int i=1;i<n;i++){
        for(int j=1;j<=v[i][0];j++){
            if(v[i][j]==x)
                return i;
        }
    }
}

int finda(int i,int x){
    int y=0;
    for(int j=1;j<=v[i][0];j++){
        if(v[i][j]==x)continue;
        if(in[v[i][j]]<in[y])
            y=v[i][j];
        else if(in[v[i][j]]==in[y]&&l[v[i][j]]>l[y])
            y=v[i][j];
    }
    return y;
}

int main(){

    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        in[0] = n+1;
        for(int i=1;i<=n;i++){
            in[i]=0;
            l[i]=0;
        }

        for(int i=1;i<n;i++){
            scanf("%d",&v[i][0]);
            for(int j=1;j<=v[i][0];j++){
                scanf("%d",&v[i][j]);
                in[v[i][j]]++;
            }
        }
        int st = 1;
        for(int i=1;i<=n;i++){
            if(in[i]==1)
                st = i;
        }
        ans[n] = st;
        for(int i=n-1;i>=1;i--){

            int x = findv(ans[i+1]);
            for(int j=1;j<=v[x][0];j++){
                in[v[x][j]]--;
                l[v[x][j]] = max(l[v[x][j]],i+1-v[x][0]);
            }

            int y = finda(x,ans[i+1]);
            ans[i]=y;
            v[x][0]=0;
        }

        for(int i=1;i<=n;i++){
            printf("%d%c",ans[i],i==n?'\n':' ');
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define MAXN 210
#define MOD 200000007
#define inf 0x3f3f3f3f

int n;
int a[MAXN];
int v[MAXN][MAXN];
int in[MAXN];
int ans[MAXN];
int l[MAXN];
int len[MAXN];

int findv(int x){

    for(int i=1;i<n;i++){
        for(int j=1;j<=v[i][0];j++){
            if(v[i][j]==x)
                return i;
        }
    }
}

int finda(int i,int x,int st,int inc){
    int y=0;
    for(int j=st;j<=v[i][0]&&j>=1;j+=inc){
        if(v[i][j]==x)continue;
        if(in[v[i][j]]<in[y])
            y=v[i][j];
        else if(in[v[i][j]]==in[y]&&l[v[i][j]]>l[y])
            y=v[i][j];
    }
    if(in[y]>1) return -1;
    return y;
}

int init(int st,int inc){
    in[0] = n+1;
    for(int i=1;i<=n;i++){
        in[i]=0;
        l[i]=0;
    }

    for(int i=1;i<n;i++){
        v[i][0]=len[i];
        for(int j=1;j<=v[i][0];j++)
            in[v[i][j]]++;
    }

    for(int i=st;i<=n&&i>=1;i+=inc){
        if(in[i]==1)
            return i;
    }
}

int solve(int st,int flag){

    ans[n] = st;
    for(int i=n-1;i>=1;i--){

        int x = findv(ans[i+1]);
        for(int j=1;j<=v[x][0];j++){
            in[v[x][j]]--;
            l[v[x][j]] = max(l[v[x][j]],i+1-v[x][0]);
        }
        int y;

        if(flag)
            y=finda(x,ans[i+1],1,1);
        else
            y=finda(x,ans[i+1],v[x][0],-1);

        if(y==-1)return 0;
        ans[i]=y;
        v[x][0]=0;
    }
    return 1;
}

int main(){

    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<n;i++){
            scanf("%d",&v[i][0]);
            len[i]=v[i][0];
            for(int j=1;j<=v[i][0];j++){
                scanf("%d",&v[i][j]);
            }
        }

        if(!solve(init(1,1),1))
            solve(init(n,-1),0);

        for(int i=1;i<=n;i++){
            printf("%d%c",ans[i],i==n?'\n':' ');
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define MAXN 210
#define MOD 200000007
#define inf 0x3f3f3f3f

int n;
int a[MAXN];
int v[MAXN][MAXN];
int in[MAXN];
int ans[MAXN];
int l[MAXN];
int len[MAXN];

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int findv(int x){

    for(int i=1;i<n;i++){
        for(int j=1;j<=v[i][0];j++){
            if(v[i][j]==x)
                return i;
        }
    }
}

int finda(int i,int x,int st,int inc){
    int y=0;
    for(int j=st;j<=v[i][0]&&j>=1;j+=inc){
        if(v[i][j]==x)continue;
        if(in[v[i][j]]>1)continue;

        if(in[v[i][j]]<in[y])
            y=v[i][j];
        else if(in[v[i][j]]==in[y]&&l[v[i][j]]>l[y])
            y=v[i][j];
    }
    if(in[y]>1) return -1;
    return y;
}

int init(int st,int inc){
    in[0] = n+1;
    for(int i=1;i<=n;i++){
        in[i]=0;
        l[i]=0;
    }

    for(int i=1;i<n;i++){
        v[i][0]=len[i];
        for(int j=1;j<=v[i][0];j++)
            in[v[i][j]]++;
    }

    for(int i=st;i<=n&&i>=1;i+=inc){
        if(in[i]==1)
            return i;
    }
}

int solve(int st,int flag){

    ans[n] = st;
    for(int i=n-1;i>=1;i--){

        int x = findv(ans[i+1]);
        for(int j=1;j<=v[x][0];j++){
            in[v[x][j]]--;
            l[v[x][j]] = max(l[v[x][j]],i+1-v[x][0]);
        }
        int y;

        if(flag)
            y=finda(x,ans[i+1],1,1);
        else
            y=finda(x,ans[i+1],v[x][0],-1);

        if(y==-1)return 0;
        ans[i]=y;
        v[x][0]=0;
    }
    return 1;
}

int main(){

    int t = readint();
    while(t--){
        n = readint();
        for(int i=1;i<n;i++){
            len[i]=readint();
            for(int j=1;j<=len[i];j++){
                v[i][j] = readint();
            }
        }

        if(!solve(init(1,1),1))
            solve(init(n,-1),0);

        for(int i=1;i<=n;i++){
            printf("%d%c",ans[i],i==n?'\n':' ');
        }
    }

    return 0;
}


#include <cstdio>
#include <cstring>
const int M = 205;
int read()
{
    int num=0,flag=1;
    char c;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    while(c>='0'&&c<='9')num=(num<<3)+(num<<1)+(c^48),c=getchar();
    return num*flag;
}
int T,n,a[M][M],ans[M],p[M],f[M];
int fuck()
{
	for(int now=2;now<=n;now++)
	{
		for(int i=2;i<=n;i++)
		{
			int r=a[i][0],x=-1;
			for(int j=1;j<=a[i][0];j++)
			{
				int b=a[i][j];
				if(!p[b]) x=b;
				else if(p[b]>=now-a[i][0]+1) r--;
			}
			if(r==1 && x!=-1)
			{
				ans[now]=x;
				p[x]=now;
				break;
			}
		}
		if(!ans[now]) return 0;
	}
	return 1;
}
signed main()
{
	T=read();
	while(T--)
	{
		n=read();
		for(int i=2;i<=n;i++)
		{
			a[i][0]=read();
			for(int j=1;j<=a[i][0];j++)
				a[i][j]=read();
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
				ans[j]=p[j]=0;
			ans[1]=i;p[i]=1;
			if(fuck()) break;
		}
		for(int i=1;i<=n;i++)
			printf("%d ",ans[i]);
		puts("");
	}
}
/*
*/


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
using namespace std;
const int maxn = 1e2 + 10;
int cnt, n, num[maxn], numl[maxn], numr[maxn];

struct Segment{
	unordered_set<int> s;
	void init() {
		s.clear();
	}
	void add(int x) {
		s.insert(x);
	}
	int has(int x) {
		return s.find(x) != s.end();
	}
	void del(int x) {
		s.erase(x);
	}
	int size() {
		return s.size();
	}
	void print() {
		for (int x : s)
			printf("%d ", x);
	}
}seg[maxn];

int main()
{
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	#endif
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		seg[cnt = 1].init();
		for (int i = 1; i <= n; ++i)
			seg[1].add(i);
		for (int i = 1, k, lp, rp, cl, cr; i < n; ++i) {
			scanf("%d", &k);
			for (int j = 1; j <= k; ++j)
				scanf("%d", &num[j]);
			lp = rp = 0;
			for (int j = 1; j <= cnt && !lp; ++j)
				for (int kk = 1; kk <= k; ++kk)
					if (seg[j].has(num[kk])) {
						lp = j; break;
					}
			for (int j = cnt; j && !rp; --j)
				for (int kk = 1; kk <= k; ++kk)
					if (seg[j].has(num[kk])) {
						rp = j; break;
					}
			cl = cr = 0;
			for (int j = 1; j <= k; ++j)
				if (seg[lp].has(num[j])) {
					numl[++cl] = num[j];
				} else if (rp != lp && seg[rp].has(num[j])) {
					numr[++cr] = num[j];
				}
			if (cl && cl < seg[lp].size()) {
				for (int j = cnt; j > lp; --j)
					seg[j + 1] = seg[j];
				++cnt; seg[lp + 1].init();
				for (int j = 1; j <= cl; ++j) {
					seg[lp].del(numl[j]);
					seg[lp + 1].add(numl[j]);
				}
				++rp;
			}
			if (cr && cr < seg[rp].size()) {
				for (int j = cnt; j >= rp; --j)
					seg[j + 1] = seg[j];
				++cnt; seg[rp].init();
				for (int j = 1; j <= cr; ++j) {
					seg[rp + 1].del(numr[j]);
					seg[rp].add(numr[j]);
				}
			}
		}
		for (int i = 1; i <= cnt; ++i)
			seg[i].print();
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
using namespace std;

int main()
{
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	#endif
	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		scanf("%d", &n);
		vector<set<int>> segs;
		for (int i = 1, k; i < n; ++i) {
			set<int> s;
			scanf("%d", &k);
			for (int j = 1, x; j <= k; ++j) {
				scanf("%d", &x);
				s.insert(x);
			}
			segs.pb(s);
		}
		for (int st = 1, fg; st <= n; ++st) {
			vector<int> ans;
			vector<set<int>> cur = segs;
			for (auto &it : cur) if (it.count(st)) it.erase(st);
			ans.pb(st); fg = 1;
			for (int i = 1, cnt, nxt; i < n; ++i) {
				cnt = nxt = 0;
				for (auto &it : cur) if (it.size() == 1) {
					if (++cnt > 1) break;
					nxt = *it.begin();
				}
				if (cnt != 1) {
					fg = 0;
					break;
				}
				for (auto &it : cur) if (it.count(nxt)) it.erase(nxt);
				ans.pb(nxt);
			}
			if (fg) {
				set<set<int>> all(segs.begin(), segs.end());
				for (int i = 1; i < n; ++i) {
					set<int> s;
					s.insert(ans[i]);
					int fd = 0;
					for (int j = i - 1; j >= 0; --j) {
						s.insert(ans[j]);
						if (all.count(s)) {
							fd = 1;
							all.erase(s);
							break;
						}
					}
					if (!fd) {
						fg = 0;
						break;
					}
				}
			}
			if (fg) {
				for (int x : ans)
					printf("%d ", x);
				puts("");
				break;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int read()
{
	int res = 0, f = 1; char c = getchar();
	while(!isdigit(c) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(isdigit(c)) res = (res<<3)+(res<<1)+(c^48), c = getchar();
	return res*f;
}

const int maxn = 2e2+10;
int n, vis[maxn], ans[maxn], p[maxn];
vector<int> a[maxn];
set<int> bel[maxn];

void work(int flag)
{
	int sum = n*(n+1)/2;
	for(int i = 1; i < n; i++)
	{
		int x;
		for(x = 1; x <= n; x++) if(x != flag && vis[x] == 1) break;
		sum -= ans[n-i+1] = x;
		int s = *bel[x].begin();
		for(int y : a[s])
		{
			bel[y].erase(s);
			vis[y]--;
		}
	}
	ans[1] = sum;
	for(int i = 1; i <= n; i++) p[ans[i]] = i;
}

int check()
{
	for(int i = 1; i <= n; i++) if(vis[ans[i]]++) return 0;
	for(int i = 1; i < n; i++)
	{
		int pos = 0, v;
		for(int x : a[i]) if(pos < p[x]) pos = p[v = x];
		int len = a[i].size();
		for(int x : a[i])
		{
			int flag = 0;
			for(int j = pos-len+1; j <= pos; j++) flag |= x == ans[j];
			if(!flag) return 0;
		}
	}
	return 1;
}

void out()
{
	for(int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n':' ');
	return;
}

int main()
{
	int T = read(); while(T--)
	{
		n = read();
		for(int i = 1; i <= n; i++)
		{
			a[i].resize(0);
			bel[i].clear();
			vis[i] = 0;
		}
		for(int i = 1, len, x; i < n; i++)
		{
			len = read();
			while(len--)
			{
				x = read();
				a[i].push_back(x);
				bel[x].insert(i);
				vis[x]++;
			}
		}
		int xx = 0, yy = 0;
		for(int i = 1; i <= n; i++) if(vis[i] == 1)
		{
			if(xx) yy = i;
			else xx = i;
		}

		work(yy);
		if(check()) out();
		else
		{
			for(int i = 1; i <= n; i++) vis[i] = 0;
			for(int i = 1; i < n; i++)
			for(int x : a[i])
			{
				bel[x].insert(i);
				vis[x]++;
			}
			work(xx);
			out();
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int read()
{
	int res = 0, f = 1; char c = getchar();
	while(!isdigit(c) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(isdigit(c)) res = (res<<3)+(res<<1)+(c^48), c = getchar();
	return res*f;
}

const int maxn = 2e2+10;
int n, vis[maxn], ans[maxn];
vector<int> a[maxn];
set<int> bel[maxn];

int main()
{
	int T = read(); while(T--)
	{
		n = read();
		for(int i = 1; i <= n; i++)
		{
			a[i].resize(0);
			bel[i].clear();
			vis[i] = 0;
		}
		for(int i = 1, len, x; i < n; i++)
		{
			len = read();
			while(len--)
			{
				x = read();
				a[i].push_back(x);
				bel[x].insert(i);
				vis[x]++;
			}
		}

		int sum = n*(n+1)/2;
		for(int i = 1; i < n; i++)
		{
			int x;
			for(x = 1; x <= n; x++) if(vis[x] == 1) break;
			sum -= ans[n-i+1] = x;
			int s = *bel[x].begin();
			for(int y : a[s])
			{
				bel[y].erase(s);
				vis[y]--;
			}
		}
		ans[1] = sum;
		for(int i = 1; i <= n; i++) printf("%d ", ans[i]); putchar(10);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int read()
{
	int res = 0, f = 1; char c = getchar();
	while(!isdigit(c) && c != '-') c = getchar();
	if(c == '-') f = -1, c = getchar();
	while(isdigit(c)) res = (res<<3)+(res<<1)+(c^48), c = getchar();
	return res*f;
}

const int maxn = 2e2+10;
int n, ans[maxn], vis[maxn];
vector<set<int> > lis;

int check()
{
	memset(vis, 0, sizeof(vis));
	for(int i = 1; i <= n; i++)
	{
		if(vis[ans[i]]) return 0;
		vis[ans[i]] = i;
	}
	for(set<int> &s : lis)
	{
		int top = 0;
		for(int x : s) top = max(top, vis[x]);
		int len = s.size();
		for(int i = top-len+1; i <= top; i++) if(!s.count(ans[i])) return 0;
	}
	return 1;
}

int main()
{
	int T = read(); while(T--)
	{
		n = read();
		lis.resize(0);
		for(int i = 1, len, x; i < n; i++)
		{
			len = read();
			set<int> s;
			while(len--) s.insert(read());
			lis.push_back(s);
		}
		for(int sta = 1; sta <= n; sta++)
		{
			vector<set<int> > tl = lis;
			int cnt = 0, x = sta;
			while(233)
			{
				ans[++cnt] = x;
				int tot = 0, y;
				for(set<int> &s : tl)
				{
					if(s.count(x)) s.erase(x);
					if(s.size() == 1) tot++, y = *s.begin();
				}
				if(tot != 1) break;
				x = y;
			}
			if(cnt == n && check())
			{
				for(int i = 1; i < n; i++) printf("%d ", ans[i]);
				printf("%d\n", ans[n]);
				break;
			}
		}
	}
	return 0;
}


#include <map>
#include <set>
#include <deque>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 205
#define LL long long
#define Pa pair<LL, LL>
#define Mod 998244353
#define Int register int
#define INF 1000000000000000000ll
using namespace std;
inline LL Min(LL x,LL y)
{
	if (x < y)
		return x;
	return y;
}
inline LL Max(LL x,LL y)
{
	if (x > y)
		return x;
	return y;
}
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' || s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline void Swap(LL &x,LL &y)
{
	LL Temp = x;
	x = y;
	y = Temp;
}
LL tot[MAXN], n, Tian[MAXN], Num[MAXN][MAXN], Endx[MAXN], c[MAXN];
set<LL> Bel[MAXN];
LL Pai[MAXN], totp;
bool Check()
{
	for (Int i = 2; i <= n; ++ i)
	{
		LL Ck = Endx[i];
		LL Gs = c[Ck];
		totp = 0;
		while (Gs --)
			Pai[++ totp] = Tian[i - totp + 1];
		sort(Pai + 1, Pai + 1 + c[Ck]);
		for (Int i = 1; i <= c[Ck]; ++ i)
			if (Pai[i] != Num[Ck][i])
				return 0;
	}
	return 1;
}
bool Dfs(LL r,LL Front)
{
	if (r == 1)
	{
		if (Front != -1)
			Tian[r] = Front;
		else
		{
			for (Int i = 1; i < MAXN; ++ i)
				if (tot[i] == 1)
				{
					Tian[r] = i;
					break;
				}
		}
		return Check();
	}
	LL a = -1, b = -1;
	for (Int i = 1; i < MAXN; ++ i)
		if (tot[i] == 1)
		{
			if (a == -1)
				a = i;
			else b = i;
		}
	if (a != -1 && b == -1)
	{
		Tian[r] = a;
		LL Gui = * Bel[a].begin();
		Endx[r] = Gui;
		for (Int i = 1; i <= c[Gui]; ++ i)
			Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
		if (! Dfs(r - 1, Front))
		{
			for (Int i = 1; i <= c[Gui]; ++ i)
				Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
			return 0;
		}
	}
	else if (a != -1)
	{
		if (Front == -1)
		{
			Tian[r] = a;
			LL Gui = * Bel[a].begin();
			Endx[r] = Gui;
			for (Int i = 1; i <= c[Gui]; ++ i)
				Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
			if (! Dfs(r - 1, b))
			{
				for (Int i = 1; i <= c[Gui]; ++ i)
					Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
				Tian[r] = b;
				Gui = * Bel[b].begin();
				Endx[r] = Gui;
				for (Int i = 1; i <= c[Gui]; ++ i)
					Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
				if (! Dfs(r - 1, a))
				{
					for (Int i = 1; i <= c[Gui]; ++ i)
						Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
					return 0;
				}
			}
		}
		else
		{
			LL Temp;
			if (a == Front)
				Temp = b;
			else Temp = a;
			LL Gui = * Bel[Temp].begin();
			Endx[r] = Gui;
			for (Int i = 1; i <= c[Gui]; ++ i)
				Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
			Tian[r] = Temp;
			if (! Dfs(r - 1, Front))
			{
				for (Int i = 1; i <= c[Gui]; ++ i)
					Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
				return 0;
			}
		}
	}
	else return 0;
	return 1;
}
int main()
{
	LL T;
	read( T );
	while (T --)
	{
		memset(tot, 0, sizeof tot);
		read( n );
		for (Int i = 1; i < n; ++ i)
		{
			read( c[i] );
			for (Int j = 1; j <= c[i]; ++ j)
			{
//				LL Num[i][j];
				read( Num[i][j] );
				Bel[Num[i][j]].insert( i );
				tot[Num[i][j]] ++;
			}
			sort(Num[i] + 1, Num[i] + 1 + c[i]);
		}
		bool PPL = Dfs(n, -1);
//		puts("sad");
		for (Int i = 1; i <= n; ++ i)
			printf("%lld ", Tian[i]);
		putchar('\n');
		for (Int i = 1; i < MAXN; ++ i)
			Bel[i].clear();
	}
	return 0;
}


#include <map>
#include <set>
#include <deque>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 205
#define LL long long
#define Pa pair<LL, LL>
#define Mod 998244353
#define Int register int
#define INF 1000000000000000000ll
using namespace std;
inline LL Min(LL x,LL y)
{
	if (x < y)
		return x;
	return y;
}
inline LL Max(LL x,LL y)
{
	if (x > y)
		return x;
	return y;
}
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' || s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline void Swap(LL &x,LL &y)
{
	LL Temp = x;
	x = y;
	y = Temp;
}
LL tot[MAXN], n, Tian[MAXN], Num[MAXN][MAXN], Endx[MAXN], c[MAXN];
set<LL> Bel[MAXN];
LL Pai[MAXN], totp;
bool Check()
{
	for (Int i = 2; i <= n; ++ i)
	{
		LL Ck = Endx[i];
		LL Gs = c[Ck];
		totp = 0;
		while (Gs --)
			Pai[++ totp] = Tian[i - totp + 1];
		sort(Pai + 1, Pai + 1 + c[Ck]);
		for (Int i = 1; i <= c[Ck]; ++ i)
			if (Pai[i] != Num[Ck][i])
				return 0;
	}
	return 1;
}
bool Dfs(LL r,LL Front)
{
	if (r == 1)
	{
		if (Front != -1)
			Tian[r] = Front;
		else
		{
			for (Int i = 1; i < MAXN; ++ i)
				if (tot[i] == 1)
				{
					Tian[r] = i;
					break;
				}
		}
		return Check();
	}
	LL a = -1, b = -1;
	for (Int i = 1; i < MAXN; ++ i)
		if (tot[i] == 1)
		{
			if (a == -1)
				a = i;
			else b = i;
		}
	if (a != -1 && b == -1)
	{
		Tian[r] = a;
		LL Gui = * Bel[a].begin();
		Endx[r] = Gui;
		for (Int i = 1; i <= c[Gui]; ++ i)
			Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
		if (! Dfs(r - 1, Front))
		{
			for (Int i = 1; i <= Gui; ++ i)
				Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
			return 0;
		}
	}
	else if (a != -1)
	{
		if (Front == -1)
		{
			Tian[r] = a;
			LL Gui = * Bel[a].begin();
			Endx[r] = Gui;
			for (Int i = 1; i <= Gui; ++ i)
				Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
			if (! Dfs(r - 1, b))
			{
				for (Int i = 1; i <= Gui; ++ i)
					Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
				Tian[r] = b;
				Gui = * Bel[b].begin();
				Endx[r] = Gui;
				for (Int i = 1; i <= Gui; ++ i)
					Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
				if (! Dfs(r - 1, a))
				{
					for (Int i = 1; i <= Gui; ++ i)
						Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
					return 0;
				}
			}
		}
		else
		{
			LL c;
			if (a == Front)
				c = b;
			else c = a;
			LL Gui = * Bel[c].begin();
			Endx[c] = Gui;
			for (Int i = 1; i <= Gui; ++ i)
				Bel[Num[Gui][i]].erase( Gui ), tot[Num[Gui][i]] --;
			Tian[r] = c;
			if (! Dfs(r - 1, Front))
			{
				for (Int i = 1; i <= Gui; ++ i)
					Bel[Num[Gui][i]].insert( Gui ), tot[Num[Gui][i]] ++;
				return 0;
			}
		}
	}
	else return 0;
	return 1;
}
int main()
{
	LL T;
	read( T );
	while (T --)
	{
		memset(tot, 0, sizeof tot);
		read( n );
		for (Int i = 1; i < n; ++ i)
		{
			read( c[i] );
			for (Int j = 1; j <= c[i]; ++ j)
			{
//				LL Num[i][j];
				read( Num[i][j] );
				Bel[Num[i][j]].insert( i );
				tot[Num[i][j]] ++;
			}
			sort(Num[i] + 1, Num[i] + 1 + c[i]);
		}
		bool PPL = Dfs(n, -1);
//		puts("sad");
		for (Int i = 1; i <= n; ++ i)
			printf("%lld ", Tian[i]);
		putchar('\n');
		for (Int i = 1; i < MAXN; ++ i)
			Bel[i].clear();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n,fq[1069],sq[1069];
vector<long long> a[1069],vl[1069];
bitset<1069> vtd;
bool r0;

void rc(long long pz,long long x)
{
	long long i,j,k,l,sz,tg[2],c=0;

	sq[pz]=x;
	if(pz==1)
	{
		r0=1;
		return;
	}
	for(i=0;vtd[vl[x][i]];i++);
	k=vl[x][i];
	vtd[k]=1;
	sz=a[k].size();
	for(i=0;i<sz;i++)
	{
		l=a[k][i];
		fq[l]--;
		if(fq[l]==1||(pz==2&&l!=x))
		{
			tg[c]=l;
			c++;
		}
	}
	for(i=0;i<c;i++)
	{
		rc(pz-1,tg[i]);
		if(r0)
		{
			return;
		}
	}
	for(i=0;i<sz;i++)
	{
		l=a[k][i];
		fq[l]++;
	}
	vtd[k]=0;
}

int main()
{
	long long t,rr,i,j,k,sz;

	scanf("%lld",&t);
	for(rr=0;rr<t;rr++)
	{
		scanf("%lld",&n);
		for(i=1;i<=n+1;i++)
		{
			a[i].clear();
			vl[i].clear();
			fq[i]=0;
			vtd[i]=0;
		}
		for(i=1;i<=n;i++)
		{
			sz=n+1;
			if(i<n)
			{
				scanf("%lld",&sz);
			}
			for(j=1;j<=sz;j++)
			{
				k=j;
				if(i<n)
				{
					scanf("%lld",&k);
				}
				a[i].push_back(k);
				vl[k].push_back(i);
				fq[k]++;
			}
		}
		r0=0;
		rc(n+1,n+1);
		for(i=1;i<=n;i++)
		{
			printf("%lld%c",sq[i]," \n"[i==n]);
		}
	}
}


//12252024832524
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
const int MAXN = 205;
int n;
int cnt[MAXN],a[MAXN][MAXN],ans[MAXN],w[MAXN];
int wdnmd[MAXN];
bool h[MAXN][MAXN];//i在j组

int Read()
{
	int x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(int x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(int x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

pair<int,int> findone()
{
	bool f = 0;
	pair<int,int> ret = make_pair(0,0);
	for(int i = 1;i <= n;++ i)
	{
		if(cnt[i] == 1)
		{
			if(f) ret.second = i;
			else ret.first = i,f = 1;
		}
	}
	return ret;
}
int findgroup(int x)
{
	for(int i = 1;i < n;++ i)
		if(h[x][i]) return i;
}
bool check()
{
	for(int i = 1;i < n;++ i)//枚举组
	{
		for(int j = 1;j <= a[i][0];++ j)
			wdnmd[j] = w[a[i][j]];
		sort(wdnmd+1,wdnmd+a[i][0]+1);
		for(int j = 2;j <= a[i][0];++ j)
			if(wdnmd[j] - 1 != wdnmd[j-1])
				return 0;
	}
	return 1;
}
bool solve(int x,int qian)
{
	if(x == 1)
	{
		ans[1] = qian;
		w[ans[1]] = 1;
		if(check()) {return 1;}
		return 0;
	}
	pair<int,int> dz = findone();
	if(!dz.first) return 0;
	if(dz.second)
	{
		if(qian)
		{
			if(qian == dz.second) ans[x] = dz.first;
			else ans[x] = dz.second;
		}
		else
		{
			int z = findgroup(dz.second);
			for(int i = 1;i <= a[z][0];++ i)
				h[a[z][i]][z] = 0,cnt[a[z][i]]--;
			ans[x] = dz.second;
			w[ans[x]] = x;
			if(solve(x-1,dz.first)) return 1;
			for(int i = 1;i <= a[z][0];++ i)
				h[a[z][i]][z] = 1,cnt[a[z][i]]++;
			qian = dz.second;
			ans[x] = dz.first;
		}
	}
	else ans[x] = dz.first;
	int z = findgroup(ans[x]);
	for(int i = 1;i <= a[z][0];++ i)
		h[a[z][i]][z] = 0,cnt[a[z][i]]--;
	w[ans[x]] = x;
	if(solve(x-1,qian)) return 1;
	for(int i = 1;i <= a[z][0];++ i)
		h[a[z][i]][z] = 1,cnt[a[z][i]]++;
	return 0;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	for(int T = Read(); T ;-- T)
	{
		n = Read();
		for(int i = 1;i <= n;++ i) cnt[i] = 0,w[i] = 0;
		for(int i = 1;i <= n;++ i)
			for(int j = 1;j <= a[i][0];++ j)
				h[a[i][j]][i] = 0;
		for(int i = 1;i < n;++ i)
		{
			a[i][0] = Read();
			for(int j = 1;j <= a[i][0];++ j)
				cnt[a[i][j] = Read()] ++,h[a[i][j]][i] = 1;
		}
		solve(n,0);
		for(int i = 1;i <= n;++ i)
			Put(ans[i],i == n ? '\n' : ' ');
	}
	return 0;
}


//12252024832524
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
const int MAXN = 205;
int n;
int cnt[MAXN],a[MAXN][MAXN],ans[MAXN],w[MAXN];
int wdnmd[MAXN];
bool h[MAXN][MAXN];//i在j组

int Read()
{
	int x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(int x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(int x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

pair<int,int> findone()
{
	bool f = 0;
	pair<int,int> ret = make_pair(0,0);
	for(int i = 1;i <= n;++ i)
	{
		if(cnt[i] == 1)
		{
			if(f) ret.second = i;
			else ret.first = i,f = 1;
		}
	}
	return ret;
}
int findgroup(int x)
{
	for(int i = 1;i < n;++ i)
		if(h[x][i]) return i;
}
bool check()
{
	for(int i = 1;i < n;++ i)//枚举组
	{
		for(int j = 1;j <= a[i][0];++ j)
			wdnmd[j] = w[a[i][j]];
		sort(wdnmd+1,wdnmd+a[i][0]+1);
		for(int j = 2;j <= a[i][0];++ j)
			if(wdnmd[j] - 1 != wdnmd[j-1])
				return 0;
	}
	return 1;
}
bool solve(int x,int qian)
{
	if(x == 1)
	{
		ans[1] = qian;
		if(check()) {printf("win!\n");return 1;}
		return 0;
	}
	pair<int,int> dz = findone();
	if(!dz.first) return 0;
	if(dz.second)
	{
		if(qian)
		{
			if(qian == dz.second) ans[x] = dz.first;
			else ans[x] = dz.second;
		}
		else
		{
			int z = findgroup(dz.second);
			for(int i = 1;i <= a[z][0];++ i)
				h[a[z][i]][z] = 0,cnt[a[z][i]]--;
			ans[x] = dz.first;
			w[ans[x]] = x;
			if(solve(x-1,dz.first)) return 1;
			for(int i = 1;i <= a[z][0];++ i)
				h[a[z][i]][z] = 1,cnt[a[z][i]]++;
			qian = dz.second;
		}
	}
	else ans[x] = dz.first;
	int z = findgroup(ans[x]);
	for(int i = 1;i <= a[z][0];++ i)
		h[a[z][i]][z] = 0,cnt[a[z][i]]--;
	w[ans[x]] = x;
	if(solve(x-1,qian)) return 1;
	for(int i = 1;i <= a[z][0];++ i)
		h[a[z][i]][z] = 1,cnt[a[z][i]]++;
	return 0;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	for(int T = Read(); T ;-- T)
	{
		n = Read();
		for(int i = 1;i <= n;++ i) cnt[i] = 0;
		for(int i = 1;i <= n;++ i)
			for(int j = 1;j <= a[i][0];++ j)
				h[a[i][j]][i] = 0;
		for(int i = 1;i < n;++ i)
		{
			a[i][0] = Read();
			for(int j = 1;j <= a[i][0];++ j)
				cnt[a[i][j] = Read()] ++,h[a[i][j]][i] = 1;
		}
		solve(n,0);
		for(int i = 1;i <= n;++ i)
			Put(ans[i],i == n ? '\n' : ' ');
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<set<int>> segs;
		for (int i = 0; i < n - 1; ++i) {
			set<int> cur;
			int k;
			cin >> k;
			for (int j = 0; j < k; ++j) {
				int x;
				cin >> x;
				cur.insert(x);
			}
			segs.push_back(cur);
		}
		for (int fst = 1; fst <= n; ++fst) {
			vector<int> ans;
			bool ok = true;
			vector<set<int>> cur = segs;
			for (auto &it : cur) if (it.count(fst)) it.erase(fst);
			ans.push_back(fst);
			for (int i = 1; i < n; ++i) {
				int cnt1 = 0;
				int nxt = -1;
				for (auto  &it : cur) if (it.size() == 1) {
					++cnt1;
					nxt = *it.begin();
				}
				if (cnt1 != 1) {
					ok = false;
					break;
				}
				for (auto &it : cur) if (it.count(nxt)) it.erase(nxt);
				ans.push_back(nxt);
			}
			if (ok) {
				set<set<int>> all(segs.begin(), segs.end());
				for (int i = 1; i < n; ++i) {
					set<int> seg;
					seg.insert(ans[i]);
					bool found = false;
					for (int j = i - 1; j >= 0; --j) {
						seg.insert(ans[j]);
						if (all.count(seg)) {
							found = true;
							all.erase(seg);
							break;
						}
					}
					if (!found) ok = false;
				}
			}
			if (ok) {
				for (auto it : ans) cout << it << " ";
				cout << endl;
				break;
			}
		}
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 205
int T, n, f;
int cnt[MAXN], ans[MAXN];
bool vis[MAXN], used[MAXN];
int p[MAXN][MAXN];

void dfs( int x ) {
	if( x == 1 ) {
		int pos, ip;
		memset( used, 0, sizeof( used ) );
		for( int i = 1;i <= n;i ++ )
			used[ans[i]] = 1;
		for( int i = 1;i <= n;i ++ )
			if( ! used[i] ) pos = i;
		for( int i = 1;i <= n;i ++ )
			if( ! ans[i] ) ip = i, ans[i] = pos;
		for( int i = 1;i < n;i ++ ) {
			memset( used, 0, sizeof( used ) );
			for( int j = 1;j <= p[i][0];j ++ )
				used[p[i][j]] = 1;
			for( int j = 2;j < n;j ++ )
				if( used[ans[j]] != used[ans[j - 1]] && used[ans[j]] != used[ans[j + 1]] ) {
					ans[ip] = 0;
					return;
				}
		}
		for( int i = 1;i <= n;i ++ )
			printf( "%d ", ans[i] );
		printf( "\n" );
		f = 1;
		return;
	}
	for( int i = 1;i <= n;i ++ )
		if( cnt[i] == 1 ) {
			ans[x] = i; int temp = -1;
			for( int k = 1;k <= n;k ++ ) {
				if( vis[k] )  continue;
				bool flag = 0;
				for( int j = 1;j <= p[k][0];j ++ )
					if( p[k][j] == i ) flag = 1;
				if( flag ) {
					vis[k] = 1, temp = k;
					for( int j = 1;j <= p[k][0];j ++ )
						cnt[p[k][j]] --;
					break;
				}
			}
			if( temp == -1 ) { ans[x] = 0; return; }
			dfs( x - 1 );
			if( f ) return;
			vis[temp] = ans[x] = 0;
			for( int j = 1;j <= p[temp][0];j ++ )
				cnt[p[temp][j]] ++;
		}
}

int main() {
	scanf( "%d", &T );
	while( T -- ) {
		f = 0;
		memset( ans, 0, sizeof( ans ) );
		memset( used, 0, sizeof( used ) );
		memset( cnt, 0, sizeof( cnt ) );
		memset( vis, 0, sizeof( vis ) );
		scanf( "%d", &n );
		for( int i = 1;i < n;i ++ ) {
			scanf( "%d", &p[i][0] );
			for( int j = 1;j <= p[i][0];j ++ )
				scanf( "%d", &p[i][j] ), cnt[p[i][j]] ++;
		}
		dfs( n );
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const ll MAXN=210;
ll t,n;
ll a[MAXN][MAXN],pos[MAXN],ans[MAXN];
bool ok(){
	for(int now=2;now<=n;now++){//从第二位开始枚举
		for(int i=1;i<n;i++){//枚举子排序
			ll r=a[i][0],x=-1;//r为当前子排序的k
			for(int k=1;k<=a[i][0];k++){
				ll b=a[i][k];//当前子排序的数
				if(!pos[b])x=b;
				else if(pos[b]>=now-a[i][0]+1)r--;//要在当前子排序中
			}
			if(r==1&&x!=-1){//r-1个数都用掉了
				ans[now]=x;
				pos[x]=now;
				break;
			}
		}
		if(ans[now]==0)return false;
	}
	return true;
}
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i][0];//输进来的k
			for(int j=1;j<=a[i][0];j++)cin>>a[i][j];
		}
		for(int i=1;i<=n;i++){//第一位1~n枚举
			for(int j=1;j<=n;j++){
				pos[j]=0;ans[j]=0;//初始化
			}
			ans[1]=i;//枚举的第一位，所以第一位设i
			pos[i]=1;//i的位置为1
			if(ok())break;//可行方案
		}
		for(int i=1;i<=n;i++)cout<<ans[i]<<' ';
		cout<<endl;
	}
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 205
int T, n, f;
int cnt[MAXN], ans[MAXN];
bool vis[MAXN], used[MAXN];
int p[MAXN][MAXN];

void dfs( int x ) {
	if( x == 1 ) {
		int pos, ip;
		memset( used, 0, sizeof( used ) );
		for( int i = 1;i <= n;i ++ )
			used[ans[i]] = 1;
		for( int i = 1;i <= n;i ++ )
			if( ! used[i] ) pos = i;
		for( int i = 1;i <= n;i ++ )
			if( ! ans[i] ) ip = i, ans[i] = pos;
		for( int i = 1;i < n;i ++ ) {
			memset( used, 0, sizeof( used ) );
			for( int j = 1;j <= p[i][0];j ++ )
				used[p[i][j]] = 1;
			for( int j = 1;j <= n;j ++ )
				if( used[ans[j]] == 1 && used[ans[j - 1]] == 0 && used[ans[j + 1]] == 0 ) {
					ans[ip] = 0;
					return;
				}
		}
		for( int i = 1;i <= n;i ++ )
			printf( "%d ", ans[i] );
		printf( "\n" );
		f = 1;
		return;
	}
	for( int i = 1;i <= n;i ++ )
		if( cnt[i] == 1 ) {
			ans[x] = i; int temp = -1;
			for( int k = 1;k < n;k ++ ) {
				if( vis[k] )  continue;
				bool flag = 0;
				for( int j = 1;j <= p[k][0];j ++ )
					if( p[k][j] == i ) flag = 1;
				if( flag ) {
					vis[k] = 1, temp = k;
					for( int j = 1;j <= p[k][0];j ++ )
						cnt[p[k][j]] --;
					break;
				}
			}
			if( temp == -1 ) { ans[x] = 0; return; }
			dfs( x - 1 );
			if( f ) return;
			vis[temp] = ans[x] = 0;
			for( int j = 1;j <= p[temp][0];j ++ )
				cnt[p[temp][j]] ++;
		}
}

int main() {
	scanf( "%d", &T );
	while( T -- ) {
		f = 0;
		memset( ans, 0, sizeof( ans ) );
		memset( used, 0, sizeof( used ) );
		memset( cnt, 0, sizeof( cnt ) );
		memset( vis, 0, sizeof( vis ) );
		scanf( "%d", &n );
		for( int i = 1;i < n;i ++ ) {
			scanf( "%d", &p[i][0] );
			for( int j = 1;j <= p[i][0];j ++ )
				scanf( "%d", &p[i][j] ), cnt[p[i][j]] ++;
		}
		dfs( n );
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <string.h>

#define MAXN 201
#define BITSPERWORD 32
#define SHIFT	5
#define MASK	0x1F
typedef int BIT[2+MAXN/BITSPERWORD];
int size(int a[]) { return a[0]; }
int  tst(int a[], int i) { return a[1+(i>>SHIFT)] & (1<<(i & MASK)); }
void set(int a[], int i) { if(!tst(a,i)) { a[1+(i>>SHIFT)] |= (1<<(i & MASK)); a[0]++; } }
void clr(int a[], int i) { if(tst(a,i)) { a[1+(i>>SHIFT)] &= ~(1<<(i & MASK)); a[0]--; } }

int n;
std::vector<int> a[MAXN];
BIT bit[MAXN], bin[MAXN];

int main()
{
void restore();

int tc;
scanf("%d",&tc);
while(tc--)
	{
	for(int i=1; i<MAXN; i++)
		a[i].clear();
	memset(bit, 0, sizeof(bit));

	scanf("%d",&n);
	for(int i=1; i<=n-1; i++)
		{
		int t,d;
		scanf("%d", &t);
		for(int j=1; j<=t; j++)
			{
			scanf("%d", &d);
			a[i].push_back(d);
			set(bit[i],d);
			}
		}
	restore();
	}
return (0);
}

typedef std::vector<int> STATE;
STATE ans;

void restore()
{
int test(int p, int d);
int is_valid(STATE& s);
void print(STATE& s);

for(int d=1; d<=n; d++)
	{
	memset(bin, 0, sizeof(bin));
	for(int i=1; i<=n-1; i++)
		{
		for(int j=0; j<a[i].size(); j++)
			set(bin[i],a[i][j]);
		}

	ans.clear();
	ans.push_back(d);
	if(test(1,d)) // 还原出了一种排列但尚不知其是否合规
		{
		//print(ans);

		if(is_valid(ans)) // 检查其是否合规
		 	{
			print(ans);
		 	return;
		 	}
		}
	}
}

int test(int p, int d) // 检查第p个位置能否放d
{
if(p == n)
	return(1);

for(int i=1; i<=n-1; i++)
	clr(bin[i],d);

int count = 0, index;
for(int i=1; i<=n-1; i++)
	if(size(bin[i])==1)
		{
		count++;
		index=i;
		}
if(count!=1)
	return(0);

for(int i=1; i<=n; i++)
	if(tst(bin[index],i))
		{
		ans.push_back(i);
		return test(p+1, i);
		}
}

int is_valid(STATE& s) // 检查输入的线段是否都是s的子线段
{
int is_equal(std::vector<int>& a, BIT bit);

int used[MAXN];
memset(used, 0, sizeof(used));

std::vector<int> seg;
for(int i=1; i<s.size(); i++)
	{
	seg.clear();
	seg.push_back(s[i]);
	for(int j=i-1; j>=0; j--)
		{
		seg.push_back(s[j]);
		for(int k=1; k<=n-1; k++)
			{
			if(!used[k] && is_equal(seg, bit[k]))
				{
				used[k]=1;
				break;
				}
			}
		}
	}
for(int i=1; i<=n-1; i++)
	if(!used[i]) return(0);
return(1);
}

int is_equal(std::vector<int>& a, BIT bit)
{
for(int i=0; i<a.size(); i++)
	if(!tst(bit, a[i]))
		return(0);
if(a.size() != size(bit))
	return(0);
return(1);
}

void print(STATE& s)
{
for(int i=0; i<s.size(); i++)
	printf("%d ", s[i]);
printf("\n");
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 205
int T, n;
bool vis[MAXN], used[MAXN], num[MAXN];
int cnt[MAXN], ans[MAXN];
int p[MAXN][MAXN];

bool check( int x ) {
	if( x == 1 ) {
		for( int i = 1;i < n;i ++ ) {
			for( int j = 1;j <= n;j ++ )
				num[j] = 0;
			int idx;
			for( int j = 1;j <= p[i][0];j ++ )
				num[p[i][j]] = 1;
			for( int j = 1;j <= n;j ++ )
				if( num[ans[j]] ) { idx = j; break; }
			for( int j = idx;j <= idx + p[i][0] - 1;j ++ )
				if( ! num[ans[j]] ) return 0;
		}
		return 1;
	}
	int sum = 0, ip;
	for( int i = 1;i <= n;i ++ )
		if( cnt[i] == 1 && ! vis[i] ) sum ++, ip = i;
	if( sum != 1 ) return 0;
	ans[x] = ip;
	int pos;
	for( int i = 1;i < n;i ++ ) {
		if( used[i] ) continue;
		bool flag = 0;
		for( int j = 1;j <= p[i][0];j ++ )
			if( ip == p[i][j] ) { flag = 1; break; }
		if( flag ) {
			pos = i, used[i] = 1;
			for( int j = 1;j <= p[i][0];j ++ )
				cnt[p[i][j]] --;
			break;
		}
	}
	bool temp = check( x - 1 );
	if( temp ) return 1;
	else {
		for( int j = 1;j <= p[pos][0];j ++ )
			cnt[p[pos][j]] ++;
		ans[x] = used[pos] = 0; return 0;
	}
}

int main() {
	scanf( "%d",&T );
	while( T -- ) {
		scanf( "%d", &n );
		for( int i = 1;i <= n;i ++ )
			ans[i] = cnt[i] = vis[i] = used[i] = 0;
		for( int i = 1;i < n;i ++ ) {
			scanf( "%d", &p[i][0] );
			for( int j = 1;j <= p[i][0];j ++ )
				scanf( "%d", &p[i][j] ), cnt[p[i][j]] ++;
		}
		for( int i = 1;i <= n;i ++ ) {
			vis[i] = 1;
			ans[1] = i;
			if( check( n ) ) break;
			vis[i] = ans[1] = 0;
		}
		for( int i = 1;i <= n;i ++ )
			printf( "%d ", ans[i] );
		printf( "\n" );
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 205
int T, n;
bool vis[MAXN], used[MAXN];
int cnt[MAXN], ans[MAXN];
int p[MAXN][MAXN];

bool check( int x ) {
	if( x == 1 ) return 1;
	int sum = 0, ip;
	for( int i = 1;i <= n;i ++ )
		if( cnt[i] == 1 && ! vis[i] ) sum ++, ip = i;
	if( sum > 1 ) return 0;
	ans[x] = ip;
	int pos;
	for( int i = 1;i < n;i ++ ) {
		if( used[i] ) continue;
		bool flag = 0;
		for( int j = 1;j <= p[i][0];j ++ )
			if( ip == p[i][j] ) { flag = 1; break; }
		if( flag ) {
			pos = i, used[i] = 1;
			for( int j = 1;j <= p[i][0];j ++ )
				cnt[p[i][j]] --;
			break;
		}
	}
	bool temp = check( x - 1 );
	if( temp ) return 1;
	else {
		for( int j = 1;j <= p[pos][0];j ++ )
			cnt[p[pos][j]] ++;
		ans[x] = used[pos] = 0; return 0;
	}
}

int main() {
	scanf( "%d",&T );
	while( T -- ) {
		scanf( "%d", &n );
		for( int i = 1;i <= n;i ++ )
			ans[i] = cnt[i] = vis[i] = used[i] = 0;
		for( int i = 1;i < n;i ++ ) {
			scanf( "%d", &p[i][0] );
			for( int j = 1;j <= p[i][0];j ++ )
				scanf( "%d", &p[i][j] ), cnt[p[i][j]] ++;
		}
		for( int i = 1;i <= n;i ++ ) {
			vis[i] = 1;
			ans[1] = i;
			if( check( n ) ) break;
			vis[i] = ans[1] = 0;
		}
		for( int i = 1;i <= n;i ++ )
			printf( "%d ", ans[i] );
		printf( "\n" );
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
inline int min(int x,int y,int z){return min(x,min(y,z));}
inline int max(int x,int y,int z){return max(x,max(y,z));}
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z){return add(add(x,y),z);}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y){return 1LL*x*y%mod;}
inline int mul(int x,int y,int z){return mul(mul(x,y),z);}
#define N 205
set<int> a[N],b[N];
int be[N],ed[N],vis[N];
int ans[N],n;
bool ok()
{
	for(int i=2;i<=n;i++)
	{
		if(ed[i]-be[i]+1!=(int)b[i].size()) return 0;
	}
	return 1;
}
int solve(int x)
{
	ans[1]=x;
	for(int i=2;i<=n;i++) a[i]=b[i];
	for(int i=2;i<=n;i++) vis[i]=0;
	for(int i=2;i<=n;i++)
	{
		if(a[i].find(x)!=a[i].end())
		{
			if(!vis[i]) vis[i]=1,be[i]=1;
			a[i].erase(x);
		}
	}
	for(int i=2;i<=n;i++)
	{
		int id=0;
		for(int j=2;j<=n;j++)
		{
			if(a[j].size()==1)
			{
				if(!id) id=j;
				else return 0;
			}
		}
		if(!id) return 0;
		ans[i]=*a[id].begin(); ed[id]=i;
		for(int j=2;j<=n;j++)
		{
			if(a[j].find(ans[i])!=a[j].end())
			{
				if(!vis[j]) vis[j]=1,be[j]=i;
				a[j].erase(ans[i]);
			}
		}
	}
	for(int i=2;i<=n;i++) if(!a[i].empty()) return 0;
	// for(int i=1;i<=n;i++) printf("%d ",ans[i]); cout<<"\n";
	// for(int i=2;i<=n;i++) printf("%d %d\n",be[i],ed[i]);
	return ok();
}
void work()
{
	n=read();
	for(int i=2;i<=n;i++) b[i].clear();
	for(int i=2;i<=n;i++)
	{
		int m=read();
		while(m--) b[i].insert(read());
	}
	for(int i=1;i<=n;i++)
	{
		if(solve(i))
		{
			for(int j=1;j<=n;j++) printf("%d ",ans[j]); cout<<"\n";
			return ;
		}
	}
}
signed main()
{
	int T=read();
	while(T--) work();
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 205
int T, n, f;
int cnt[MAXN], ans[MAXN];
bool vis[MAXN], used[MAXN];
int p[MAXN][MAXN];

void dfs( int x ) {
	if( x == 1 ) {
		int pos;
		for( int i = 1;i <= n;i ++ )
			used[ans[i]] = 1;
		for( int i = 1;i <= n;i ++ )
			if( ! used[i] ) pos = i;
		for( int i = 1;i <= n;i ++ )
			printf( "%d ", ans[i] ? ans[i] : pos );
		printf( "\n" );
		f = 1;
		return;
	}
	for( int i = 1;i <= n;i ++ )
		if( cnt[i] == 1 ) {
			ans[x] = i; int temp = -1;
			for( int k = 1;k <= n;k ++ ) {
				if( vis[k] )  continue;
				bool flag = 0;
				for( int j = 1;j <= p[k][0];j ++ )
					if( p[k][j] == i ) flag = 1;
				if( flag ) {
					vis[k] = 1, temp = k;
					for( int j = 1;j <= p[k][0];j ++ )
						cnt[p[k][j]] --;
					break;
				}
			}
			if( temp == -1 ) return;
			dfs( x - 1 );
			if( f ) return;
			vis[temp] = 0;
			for( int j = 1;j <= p[temp][0];j ++ )
				cnt[p[temp][j]] ++;
		}
}

int main() {
	scanf( "%d", &T );
	while( T -- ) {
		f = 0;
		memset( used, 0, sizeof( used ) );
		memset( cnt, 0, sizeof( cnt ) );
		memset( vis, 0, sizeof( vis ) );
		scanf( "%d", &n );
		for( int i = 1;i < n;i ++ ) {
			scanf( "%d", &p[i][0] );
			for( int j = 1;j <= p[i][0];j ++ )
				scanf( "%d", &p[i][j] ), cnt[p[i][j]] ++;
		}
		dfs( n );
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 205
#define FOR(i,a,b) for(i=a;i<=b;++i)
#define REV(i,b,a) for(i=b;i>=a;--i)
#define ll long long
#define sz(a) (ll)a.size()
#define endlf "\n"<<flush
ll t,n,k,i,j,v,val;
ll p[MAXN];
#define INF 10000
void swap(ll &a, ll &b){ll tmp=b;b=a;a=tmp;}

void solve(){
	cin>>n;
	vector<int> cnt(n+1,0), scnt(n+1,0);
	// FOR(i,1,n){
	// 	cin>>p[i];

	// }

	vector<vector<int> > srtseg(n);
	vector<vector<int> > prsntIn(n+1);
	FOR(i,1,n-1){
		cin>>k;
		FOR(j,1,k){
			cin>>v;
			cnt[v]++;
			scnt[v]++;
			// if(cnt[v]==1){val=v;}
			srtseg[i].push_back(v);
			prsntIn[v].push_back(i);
		}
	}
	bool dblchk=false;ll dval;
	FOR(i,1,n){if(cnt[i]==1){val=i;}}
	FOR(i,1,n){if(cnt[i]==1 && i!=val){dblchk=true;dval=i;}}
	// cout<<val;
	// cout<<endlf;exit(0);
	// FOR(i,1,n){
	// 	FOR(j,0,sz(prsntIn[i])-1){
	// 		cout<< prsntIn[i][j]<<" ";
	// 	}
	// 	cout<<endlf;
	// }
	// exit(0);
	vector<int> ans(n+1,0);
	vector<int> rmvd(n,0);
	bool flg2=false;
	while(1){
		ans=vector<int>(n+1,0);
		rmvd=vector<int>(n,0);
		FOR(i,1,n){cnt[i]=scnt[i];}
		ans[n]=val;
		REV(i,n-1,1){
			ll seg,nval,mcnt=-INF;
			// FOR(j,1,n-1){cout<<rmvd[j]<<" ";}
			bool flag=0;
			FOR(seg, 0, sz(prsntIn[val])-1){
				if(!rmvd[prsntIn[val][seg]]){
					ll num;
					FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
						ll gt=srtseg[prsntIn[val][seg]][num];
						// cout<<gt<<' ';
						cnt[gt]--;
						if((cnt[gt]==1 && gt!=val)||(i==1&& gt!=val))
							{
								if(flag==1){
									if(scnt[gt]>scnt[nval]){
										nval=gt;
									}
								}
								else{
									nval=gt;flag=1;
								}
							}
					}
					// cout<<endlf;
					rmvd[prsntIn[val][seg]]=1;
				}
			}
			if(flag==0){
				flg2=1;
				break;
			}
			val=nval;
			ans[i]=val;
		}
		if(!flg2){break;}
		else{flg2=0;val=dval;}
	}

	if(scnt[ans[1]]>scnt[ans[2]]){swap(ans[1],ans[2]);}
	FOR(i,1,n){
		cout<<ans[i]<<' '<<flush;
	}
	cout<<endlf;
}

int main(int argc, char ** agrv){
	cin>>t;
	while(t--){solve();}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define MAXN 205
#define FOR(i,a,b) for(i=a;i<=b;++i)
#define REV(i,b,a) for(i=b;i>=a;--i)
#define ll long long
#define sz(a) (ll)a.size()
#define endlf "\n"<<flush
#define vi vector<int>
#define vvi vector<vector<int> >
ll t,n,k,i,j,v,val,seg,sol;
ll p[MAXN];
ll vstd[MAXN];

#define INF 10000
void swap(ll &a, ll &b){ll tmp=b;b=a;a=tmp;}

void display(ll st, ll en,vi &vect,string msg){
	cout<<msg<<endlf;
	ll idx;
	FOR(idx,st,en){cout<<vect[idx]<<" ";}
	cout<<endlf;
}

bool check(vi &ans, vvi &seg, vvi &have){

	// display(1,n,ans,"iaCHHHns");
	ll a,b,c;
	// cout<<"Have"<<endlf;
	// FOR(a,1,n){
	// 	FOR(b,1,n){
	// 		cout<<have[a][b]<<' ';
	// 	}
	// 	cout<<endlf;
	// }
	// cout<<"seg"<<endlf;
	// FOR(a,1,n){
	// 	FOR(b,1,sz(seg[a])){
	// 		cout<<seg[a][b-1]<<' ';
	// 	}
	// 	cout<<endlf;
	// }

	FOR(b,1,n-1){
		ll flg=0;
		// cout<<"b:"<<b<<endlf;
		FOR(a,1,n-sz(seg[b])+1){
			ll flg2=1;
			FOR(c,a,a+sz(seg[b])-1){
				if(have[b][ans[c]]!=1){
					flg2=0;break;
				}
			}

			if(flg2==1){/*cout<<"D:"<<b<<endlf;*/flg=1;break;}
		}
		if(flg==0){return false;}
	}
	return true;
}

bool recsolve(ll pos, ll uq, vi &ans, vi &rmvd, vi &cnt, vi &scnt, vvi &srtseg, vvi &prsntIn, vvi &have){

	// cout<<"POS:"<<pos<<endlf;
	// display(1,n,ans,"ans");
	// display(1,n-1,rmvd,"rmvd");
	// display(1,n,cnt,"cnt");

	vector<int> pval,solns;

	if(pos==2){
		FOR(i,1,n){if(cnt[i]==1){pval.push_back(i);}}
		FOR(i,0,1){
			ans[1]=pval[i];
			ans[2]=pval[1-i];
			// display(1,n,ans,"aCnHs");
			if(check(ans,srtseg,have)){return true;};
		}
		return false;
	}
	ll mval=-INF;
	FOR(i,1,n){
		if(cnt[i]==1){
			if(scnt[i]>mval){mval=scnt[i];}
		}
	}
	FOR(i,1,n){
		if(cnt[i]==1){
			if(scnt[i]==mval){
				pval.push_back(i);}
		}
	}
	if(sz(pval)>1){
		if(uq==true){return false;}
		// cout<<"POS:"<<pos;
		uq=true;
	}
	if(sz(pval)==0){return false;}

	FOR(sol,0, sz(pval)-1){
		ans[pos]=pval[sol];
		ll val=pval[sol];
		FOR(seg, 0, sz(prsntIn[val])-1){
			if(!rmvd[prsntIn[val][seg]]){
				ll num;
				FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
					ll gt=srtseg[prsntIn[val][seg]][num];
					cnt[gt]--;
				}
				rmvd[prsntIn[val][seg]]=1;
				if(recsolve(pos-1,uq,ans,rmvd,cnt,scnt,srtseg,prsntIn,have)){return true;}
				FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
					ll gt=srtseg[prsntIn[val][seg]][num];
					cnt[gt]++;
				}
				rmvd[prsntIn[val][seg]]=0;

			}
		}
	}
	return false;
}

void solve(){
	cin>>n;
	vector<int> cnt(n+1,0),scnt(n+1,0);
	vector<vector<int> > srtseg(n);
	vector<vector<int> > prsntIn(n+1);
	vector<vector<int> > have(n+1,vi(n+1));
	FOR(i,1,n-1){
		cin>>k;
		FOR(j,1,k){
			cin>>v;
			cnt[v]++;
			scnt[v]++;
			srtseg[i].push_back(v);
			have[i][v]=1;
			prsntIn[v].push_back(i);
		}
	}
	vector<int> ans(n+1,0);
	vector<int> rmvd(n,0);
	// display(1,n,ans,"ians");
	// display(1,n-1,rmvd,"irmvd");
	// display(1,n,cnt,"icnt");
	// display(1,n,scnt,"iscnt");
	if(!recsolve(n,false,ans,rmvd,cnt,scnt,srtseg,prsntIn,have)){cout<<"Problem";};

	FOR(i,1,n){
		cout<<ans[i]<<' ';
	}
	cout<<endl;
}

	// bool flg2=false;
	// while(1){
	// 	ans=vector<int>(n+1,0);
	// 	rmvd=vector<int>(n,0);
	// 	FOR(i,1,n){cnt[i]=scnt[i];}
	// 	ans[n]=val;
	// 	REV(i,n-1,1){
	// 		ll seg,nval,mcnt=-INF;
	// 		// FOR(j,1,n-1){cout<<rmvd[j]<<" ";}
	// 		bool flag=0;
	// 		FOR(seg, 0, sz(prsntIn[val])-1){
	// 			if(!rmvd[prsntIn[val][seg]]){
	// 				ll num;
	// 				FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
	// 					ll gt=srtseg[prsntIn[val][seg]][num];
	// 					// cout<<gt<<' ';
	// 					cnt[gt]--;
	// 					if((cnt[gt]==1 && gt!=val)||(i==1&& gt!=val))
	// 						{
	// 							if(flag==1){
	// 								if(scnt[gt]>scnt[nval]){
	// 									nval=gt;
	// 								}
	// 							}
	// 							else{
	// 								nval=gt;flag=1;
	// 							}
	// 						}
	// 				}
	// 				rmvd[prsntIn[val][seg]]=1;
	// 			}
	// 		}
	// 		if(flag==0){
	// 			flg2=1;
	// 			break;
	// 		}
	// 		val=nval;
	// 		ans[i]=val;
	// 	}

	// 	if(!flg2){break;}
	// 	else{flg2=0;val=dval;}

	// }
	// if(scnt[ans[1]]>scnt[ans[2]]){swap(ans[1],ans[2]);}
	// FOR(i,1,n){
	// 	cout<<ans[i]<<' '<<flush;
	// }
	// cout<<endlf;

int main(int argc, char ** agrv){
	cin>>t;
	while(t--){solve();}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 205
#define FOR(i,a,b) for(i=a;i<=b;++i)
#define REV(i,b,a) for(i=b;i>=a;--i)
#define ll long long
#define sz(a) (ll)a.size()
#define endlf "\n"<<flush
ll t,n,k,i,j,v,val;
ll p[MAXN];

void swap(ll &a, ll &b){ll tmp=b;b=a;a=tmp;}

void solve(){
	cin>>n;
	vector<int> cnt(n+1,0), scnt(n+1,0);
	// FOR(i,1,n){
	// 	cin>>p[i];

	// }

	vector<vector<int> > srtseg(n);
	vector<vector<int> > prsntIn(n+1);
	FOR(i,1,n-1){
		cin>>k;
		FOR(j,1,k){
			cin>>v;
			cnt[v]++;
			scnt[v]++;
			// if(cnt[v]==1){val=v;}
			srtseg[i].push_back(v);
			prsntIn[v].push_back(i);
		}
	}
	bool dblchk=false;ll dval;
	FOR(i,1,n){if(cnt[i]==1){val=i;}}
	FOR(i,1,n){if(cnt[i]==1 && i!=val){dblchk=true;dval=i;}}
	// cout<<val;
	// cout<<endlf;exit(0);
	// FOR(i,1,n){
	// 	FOR(j,0,sz(prsntIn[i])-1){
	// 		cout<< prsntIn[i][j]<<" ";
	// 	}
	// 	cout<<endlf;
	// }
	// exit(0);
	vector<int> ans(n+1,0);
	vector<int> rmvd(n,0);
	bool flg2=false;
	while(1){
		ans=vector<int>(n+1,0);
		rmvd=vector<int>(n,0);
		FOR(i,1,n){cnt[i]=scnt[i];}
		ans[n]=val;
		REV(i,n-1,1){
			ll seg,nval;
			// FOR(j,1,n-1){cout<<rmvd[j]<<" ";}
			bool flag=0;
			FOR(seg, 0, sz(prsntIn[val])-1){
				if(!rmvd[prsntIn[val][seg]]){
					ll num;
					FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
						ll gt=srtseg[prsntIn[val][seg]][num];
						// cout<<gt<<' ';
						cnt[gt]--;
						if((cnt[gt]==1 && gt!=val)||(i==1&& gt!=val)){nval=gt;flag=1;}
					}
					// cout<<endlf;
					rmvd[prsntIn[val][seg]]=1;
				}
			}
			if(flag==0){
				flg2=1;
				break;
			}
			val=nval;
			ans[i]=val;
		}
		if(!flg2){break;}
		else{flg2=0;val=dval;}
	}

	if(scnt[ans[1]]>scnt[ans[2]]){swap(ans[1],ans[2]);}
	FOR(i,1,n){
		cout<<ans[i]<<' '<<flush;
	}
	cout<<endlf;
}

int main(int argc, char ** agrv){
	cin>>t;
	while(t--){solve();}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define MAXN 205
#define FOR(i,a,b) for(i=a;i<=b;++i)
#define REV(i,b,a) for(i=b;i>=a;--i)
#define ll long long
#define sz(a) (ll)a.size()
#define endlf "\n"<<flush
#define vi vector<int>
#define vvi vector<vector<int> >
ll t,n,k,i,j,v;
ll p[MAXN];
ll vstd[MAXN];

#define INF 10000
void swap(ll &a, ll &b){ll tmp=b;b=a;a=tmp;}

void display(ll st, ll en,vi &vect,string msg){
	cout<<msg<<endlf;
	ll idx;
	FOR(idx,st,en){cout<<vect[idx]<<" ";}
	cout<<endlf;
}

bool check(vi &ans, vvi &seg, vvi &have){

	// display(1,n,ans,"iaCHHHns");
	ll a,b,c;
	// cout<<"Have"<<endlf;
	// FOR(a,1,n-1){
	// 	FOR(b,1,n){
	// 		cout<<have[a][b]<<' ';
	// 	}
	// 	cout<<endlf;
	// }
	// cout<<"seg"<<endlf;
	// FOR(a,1,n-1){
	// 	FOR(b,1,sz(seg[a])){
	// 		cout<<seg[a][b-1]<<' ';
	// 	}
	// 	cout<<endlf;
	// }

	FOR(b,1,n-1){
		ll flg=0;
		// cout<<"b:"<<b<<endlf;
		FOR(a,1,n-sz(seg[b])+1){
			ll flg2=1;
			FOR(c,a,a+sz(seg[b])-1){
				if(have[b][ans[c]]!=1){
					flg2=0;break;
				}
			}

			if(flg2==1){/*cout<<"D:"<<b<<endlf;*/flg=1;break;}
		}
		if(flg==0){return false;}
	}
	return true;
}

bool recsolve(ll pos, ll uq, vi &ans, vi &rmvd, vi &cnt, vi &scnt, vvi &srtseg, vvi &prsntIn, vvi &have){

	// cout<<"POS:"<<pos<<endlf;
	// display(1,n,ans,"ans");
	// display(1,n-1,rmvd,"rmvd");
	// display(1,n,cnt,"cnt");

	vector<int> pval,solns;

	if(pos==2){
		FOR(i,1,n){if(cnt[i]==1){pval.push_back(i);}}
		FOR(i,0,1){
			ans[1]=pval[i];
			ans[2]=pval[1-i];
			// display(1,n,ans,"aCnHs");
			if(check(ans,srtseg,have)){return true;};
		}
		return false;
	}
	ll mval=-INF;
	FOR(i,1,n){
		if(cnt[i]==1){
			if(scnt[i]>mval){mval=scnt[i];}
		}
	}
	FOR(i,1,n){
		if(cnt[i]==1){
			if(scnt[i]==mval){
				pval.push_back(i);}
		}
	}
	if(sz(pval)>1){
		if(uq==true){return false;}
		// cout<<"POS:"<<pos;
		uq=true;
	}
	if(sz(pval)==0){return false;}
	// display(0,sz(pval)-1,pval,"pval");

	ll sol,val,seg;
	FOR(sol,0, sz(pval)-1){
		// cout<<"Enter"<<pos<<" "<<pval[sol]<<endlf;
		// display(1,n-1,rmvd,"rmvd");
		ans[pos]=pval[sol];
		val=pval[sol];
		FOR(seg, 0, sz(prsntIn[val])-1){
			if(!rmvd[prsntIn[val][seg]]){
				ll num;
				FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
					ll gt=srtseg[prsntIn[val][seg]][num];
					cnt[gt]--;
				}
				rmvd[prsntIn[val][seg]]=1;
				if(recsolve(pos-1,uq,ans,rmvd,cnt,scnt,srtseg,prsntIn,have)){return true;}
				FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
					ll gt=srtseg[prsntIn[val][seg]][num];
					cnt[gt]++;
				}
				rmvd[prsntIn[val][seg]]=0;
				break;
			}
		}
		// cout<<"Exit"<<pos<<" "<<pval[sol]<<endlf;
		// display(1,n-1,rmvd,"rmvd");
	}
	return false;
}

void solve(){
	cin>>n;
	vector<int> cnt(n+1,0),scnt(n+1,0);
	vector<vector<int> > srtseg(n);
	vector<vector<int> > prsntIn(n+1);
	vector<vector<int> > have(n+1,vi(n+1));
	FOR(i,1,n-1){
		cin>>k;
		FOR(j,1,k){
			cin>>v;
			cnt[v]++;
			scnt[v]++;
			srtseg[i].push_back(v);
			have[i][v]=1;
			prsntIn[v].push_back(i);
		}
	}
	vector<int> ans(n+1,0);
	vector<int> rmvd(n,0);
	// display(1,n,ans,"ians");
	// display(1,n-1,rmvd,"irmvd");
	// display(1,n,cnt,"icnt");
	// display(1,n,scnt,"iscnt");
	if(!recsolve(n,false,ans,rmvd,cnt,scnt,srtseg,prsntIn,have)){cout<<"Problem";};

	FOR(i,1,n){
		cout<<ans[i]<<' ';
	}
	cout<<endl;
}

	// bool flg2=false;
	// while(1){
	// 	ans=vector<int>(n+1,0);
	// 	rmvd=vector<int>(n,0);
	// 	FOR(i,1,n){cnt[i]=scnt[i];}
	// 	ans[n]=val;
	// 	REV(i,n-1,1){
	// 		ll seg,nval,mcnt=-INF;
	// 		// FOR(j,1,n-1){cout<<rmvd[j]<<" ";}
	// 		bool flag=0;
	// 		FOR(seg, 0, sz(prsntIn[val])-1){
	// 			if(!rmvd[prsntIn[val][seg]]){
	// 				ll num;
	// 				FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
	// 					ll gt=srtseg[prsntIn[val][seg]][num];
	// 					// cout<<gt<<' ';
	// 					cnt[gt]--;
	// 					if((cnt[gt]==1 && gt!=val)||(i==1&& gt!=val))
	// 						{
	// 							if(flag==1){
	// 								if(scnt[gt]>scnt[nval]){
	// 									nval=gt;
	// 								}
	// 							}
	// 							else{
	// 								nval=gt;flag=1;
	// 							}
	// 						}
	// 				}
	// 				rmvd[prsntIn[val][seg]]=1;
	// 			}
	// 		}
	// 		if(flag==0){
	// 			flg2=1;
	// 			break;
	// 		}
	// 		val=nval;
	// 		ans[i]=val;
	// 	}

	// 	if(!flg2){break;}
	// 	else{flg2=0;val=dval;}

	// }
	// if(scnt[ans[1]]>scnt[ans[2]]){swap(ans[1],ans[2]);}
	// FOR(i,1,n){
	// 	cout<<ans[i]<<' '<<flush;
	// }
	// cout<<endlf;

int main(int argc, char ** agrv){
	cin>>t;
	while(t--){solve();}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 205
#define FOR(i,a,b) for(i=a;i<=b;++i)
#define REV(i,b,a) for(i=b;i>=a;--i)
#define ll long long
#define sz(a) (ll)a.size()
#define endlf "\n"<<flush
ll t,n,k,i,j,v,val;
ll p[MAXN];

void swap(ll &a, ll &b){ll tmp=b;b=a;a=tmp;}

void solve(){
	cin>>n;
	vector<int> cnt(n+1,0), scnt(n+1,0);
	// FOR(i,1,n){
	// 	cin>>p[i];

	// }

	vector<vector<int> > srtseg(n);
	vector<vector<int> > prsntIn(n+1);
	FOR(i,1,n-1){
		cin>>k;
		FOR(j,1,k){
			cin>>v;
			cnt[v]++;
			scnt[v]++;
			// if(cnt[v]==1){val=v;}
			srtseg[i].push_back(v);
			prsntIn[v].push_back(i);
		}
	}

	FOR(i,1,n){if(cnt[i]==1){val=i;}}
	// cout<<val;
	// cout<<endlf;exit(0);
	// FOR(i,1,n){
	// 	FOR(j,0,sz(prsntIn[i])-1){
	// 		cout<< prsntIn[i][j]<<" ";
	// 	}
	// 	cout<<endlf;
	// }
	// exit(0);
	vector<int> ans(n+1,0);
	vector<int> rmvd(n,0);
	ans[n]=val;
	REV(i,n-1,1){
		ll seg,nval;
		// FOR(j,1,n-1){cout<<rmvd[j]<<" ";}
		FOR(seg, 0, sz(prsntIn[val])-1){
			if(!rmvd[prsntIn[val][seg]]){
				ll num;
				FOR(num, 0, sz(srtseg[prsntIn[val][seg]])-1){
					ll gt=srtseg[prsntIn[val][seg]][num];
					// cout<<gt<<' ';
					cnt[gt]--;
					if((cnt[gt]==1 && gt!=val)||(i==1&& gt!=val)){nval=gt;}
				}
				// cout<<endlf;
				rmvd[prsntIn[val][seg]]=1;
			}
		}
		val=nval;
		ans[i]=val;
	}
	if(scnt[ans[1]]>scnt[ans[2]]){swap(ans[1],ans[2]);}
	FOR(i,1,n){
		cout<<ans[i]<<' '<<flush;
	}
	cout<<endlf;
}

int main(int argc, char ** agrv){
	cin>>t;
	while(t--){solve();}
}


#include <bits/stdc++.h>
#define TASK "1343F"
#define pb push_back
#define ii pair<int,int>
#define ll long long
#define F first
#define S second
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FOr(i, a, b) for (int i=a; i<b ; i++)
#define FOD(i, a, b) for (int i=a; i>=b; i--)
#define FOd(i, a, b) for (int i=a; i>b ; i--)
using namespace std;
const int N=209;
int a[N][N], b[N][N];
int ft[N], sz[N];
vector<int> p[N],ans;
vector<ii> can;
int t,n;
int main()
{
    cin>>t;
    while(t--) {
        cin>>n;
        FOR(i,1,n-1) {
            int l;
            cin>>l;
            a[i][0]=l;
            sz[i]=l;
            FOR(j, 1, l) {
                int u;
                cin>>u;
                if (l==2) can.pb({u,i});
                a[i][u]=1;
                p[u].push_back(i);
            }
        }
        FOR(i,0,n)
            FOR(j,0,n)
                b[i][j]=a[i][j];
        FOR(x,0,can.size()-1) {
            FOR(i, 1, n-1)
                ft[i]=0;
            int val=can[x].F;
            int fp=can[x].S;
            FOR(i,0,n)
            FOR(j,0,n)
                a[i][j]=b[i][j];
            ans.clear();
            ans.pb(val);
            vector<int> nxt;
            //ans.pb(val2);
            FOR(now, 2, n) {
                nxt.clear();
                FOR(i, 1, n-1)
                    if (a[i][val]) {
                        a[i][val]=0;
                        a[i][0]--;
                        if (a[i][0]==1) nxt.pb(i);
                        if (!ft[i]) ft[i]=now-1;
                    }
            if (nxt.size() == 0 || nxt.size() >1) break;
            fp=nxt[0];
            if (sz[fp] != now - ft[fp] + 1) break;
            FOR(j, 1, n)
                if (a[fp][j]==1) val=j;
            ans.pb(val);
            }
            if (ans.size()==n) break;
        }
        FOR(i, 0, n)
            FOR(j, 0, n)
                a[i][j]=0;
        FOR(i, 0, n-1)
            cout << ans[i] << " ";
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
#define TASK "1343F"
#define pb push_back
#define ii pair<int,int>
#define ll long long
#define F first
#define S second
#define FOR(i, a, b) for (int i=a; i<=b; i++)
#define FOr(i, a, b) for (int i=a; i<b ; i++)
#define FOD(i, a, b) for (int i=a; i>=b; i--)
#define FOd(i, a, b) for (int i=a; i>b ; i--)
using namespace std;
const int N=209;
int a[N][N], b[N][N];
int ft[N], sz[N], ok[N], cnt[N];;
vector<int> ans;
vector<ii> can;
int t,n;
void n_3() {
    freopen(TASK".INP","r",stdin);
    freopen(TASK".OUT","w",stdout);
    cin>>t;
    while(t--) {
        cin>>n;
        FOR(i,1,n-1) {
            int l;
            cin>>l;
            a[i][0]=l;
            sz[i]=l;
            FOR(j, 1, l) {
                int u;
                cin>>u;
                if (l==2) can.pb({u,i});
                a[i][u]=1;
            }
        }
        FOR(i,0,n)
            FOR(j,0,n)
                b[i][j]=a[i][j];
        FOR(x,0,can.size()-1) {
            FOR(i, 1, n-1)
                ft[i]=0;
            int val=can[x].F;
            int fp=can[x].S;
            FOR(i,0,n)
            FOR(j,0,n)
                a[i][j]=b[i][j];
            ans.clear();
            ans.pb(val);
            vector<int> nxt;
            //ans.pb(val2);
            FOR(now, 2, n) {
                nxt.clear();
                FOR(i, 1, n-1)
                    if (a[i][val]) {
                        a[i][val]=0;
                        a[i][0]--;
                        if (a[i][0]==1) nxt.pb(i);
                        if (!ft[i]) ft[i]=now-1;
                    }
            if (nxt.size() == 0 || nxt.size() >1) break;
            fp=nxt[0];
            if (sz[fp] != now - ft[fp] + 1) break;
            FOR(j, 1, n)
                if (a[fp][j]==1) val=j;
            ans.pb(val);
            }
            if (ans.size()==n) break;
        }
        FOR(i, 0, n)
            FOR(j, 0, n)
                a[i][j]=0;
        FOR(i, 0, n-1)
            cout << ans[i] << " ";
        cout<<"\n";
    }
}
void n_2() {
    cin>>t;
    while(t--) {
        cin>>n;
        FOR(i,1,n-1) {
            int l;
            cin>>l;
            a[i][0]=l;
            FOR(j, 1, l) {
                int u;
                cin>>u;
                ++cnt[u];
                a[i][u]=1;
            }
        }
        vector<int> try_;
        FOR(i,1,n)
            if (cnt[i]==1) try_.pb(i);
        for(int vlast:try_) {
            vector<int> ans(n);
            vector<int> used(n+1,0);
            int pnow;
            FOR(i, 1, n) cnt[i]=ft[i]=0;
            FOR(i,1,n)
                FOR(j,1,n)
                    if (a[i][j]) cnt[j]++;

            FOD(i, n-2, 1) {
                ans[i+1]=vlast;
                FOR(j, 1, n-1)
                    if (a[j][vlast]==1 && !ok[j])
                        pnow=j;
                ok[pnow]=1;
                used[pnow]=1;

                FOR(j, 1, n)
                    if (a[pnow][j]) {
                        cnt[j]--;
                        if (cnt[j]==1) vlast=j;
                        ft[j]=max(ft[j],i+2-a[pnow][0]+1);
                    }

            }
            FOR(i, 1, n-1)
                if (used[i] == 0 && a[i][0]!=2) continue;
            FOR(i, 1, n-1)
                ok[ans[i]]=2;
            vector<int> tp;
            FOR(i, 1, n)
                if (ok[i]!=2) tp.pb(i);
            ans[1]=tp[1];
            ans[0]=tp[0];
            if (ft[tp[0]] > 1) ans[1]=tp[0] ,ans[0]=tp[1];
            FOR(i, 0, n-1)
                cout<<ans[i]<<" ";
            cout<< "\n";
            FOR(i, 1, n)
                cnt[i]=ft[i]=ok[i]=0;
            FOR(i, 0, n)
                FOR(j, 1, n)
                    a[i][j]=0;
            break;
        }
    }
}
int main() {
    n_2();
}