Problem: We guessed a permutation p consisting of n integers. The permutation of length n is the array of length n where each element from 1 to n appears exactly once. This permutation is a secret for you.

For each position r from 2 to n we chose some other index l (l < r) and gave you the segment p_l, p_{l + 1}, ..., p_r in sorted order (i.e. we rearranged the elements of this segment in a way that the elements of this segment are sorted). Thus, you are given exactly n-1 segments of the initial permutation but elements inside each segment are sorted. The segments are given to you in random order.

For example, if the secret permutation is p=[3, 1, 4, 6, 2, 5] then the possible given set of segments can be:

  * [2, 5, 6] 
  * [4, 6] 
  * [1, 3, 4] 
  * [1, 3] 
  * [1, 2, 4, 6] 



Your task is to find any suitable permutation (i.e. any permutation corresponding to the given input data). It is guaranteed that the input data corresponds to some permutation (i.e. such permutation exists).

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow.

The first line of the test case contains one integer n (2 ≤ n ≤ 200) — the length of the permutation.

The next n-1 lines describe given segments.

The i-th line contains the description of the i-th segment. The line starts with the integer k_i (2 ≤ k_i ≤ n) — the length of the i-th segment. Then k_i integers follow. All integers in a line are distinct, sorted in ascending order, between 1 and n, inclusive.

It is guaranteed that the required p exists for each test case.

It is also guaranteed that the sum of n over all test cases does not exceed 200 (∑ n ≤ 200).

Output

For each test case, print the answer: n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, all p_i should be distinct) — any suitable permutation (i.e. any permutation corresponding to the test case input).

Example

Input


5
6
3 2 5 6
2 4 6
3 1 3 4
2 1 3
4 1 2 4 6
5
2 2 3
2 1 2
2 1 4
2 4 5
7
3 1 2 6
4 1 3 5 6
2 1 2
3 4 5 7
6 1 2 3 4 5 6
3 1 3 6
2
2 1 2
5
2 2 5
3 2 3 5
4 2 3 4 5
5 1 2 3 4 5


Output


3 1 4 6 2 5 
3 2 1 4 5 
2 1 6 3 5 4 7 
1 2 
2 5 3 4 1 

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		for(int q=ni();q>0;q--) {
			work();
			out.println();
		}
		out.flush();
	}
	long mod=998244353L;
	long inf=Long.MAX_VALUE;
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	int[] degree;
	int[][] rec;
	int n;
	void work() {
		n=ni();
		ArrayList<HashSet<Integer>> list;
		degree=new int[n+1];
		rec=new int[n-1][];
		list=new ArrayList<>();
		for(int i=0;i<n-1;i++) {
			int j=ni();
			int[] A=new int[j];
			HashSet<Integer> set=new HashSet<>();
			for(;j>0;j--) {
				int v=ni();
				A[j-1]=v;
				degree[v]++;
				set.add(v);
			}
			rec[i]=A;
			list.add(set);
		}
		List<Integer> ret=new ArrayList<>();
		for(int i=n;i>=1;i--) {
			int m1=0,m2=0;
			for(int j=1;j<=n;j++) {
				if(degree[j]==1) {
					if(m1==0) {
						m1=j;
					}else {
						m2=j;
					}
				}
			}
			if(m1>0&&m2>0) {
				List<Integer> l1=new ArrayList<>(ret);
				List<Integer> l2=new ArrayList<>(ret);
				ArrayList<HashSet<Integer>> list2=new ArrayList<>();
				for(HashSet<Integer> s:list) {
					list2.add(new HashSet<>(s));
				}
				if(find(l1,m1,degree.clone(),list)) {
					ret=l1;
				}else if(find(l2,m2,degree.clone(),list2)){
					ret=l2;
				}
				break;
			}else {
				ret.add(m1);
				for(int j=0;j<list.size();j++) {
					HashSet<Integer> s=list.get(j);
					if(s.contains(m1)) {
						for(Integer v:s) {
							degree[v]--;
						}
						list.remove(j);
						break;
					}
				}
			}
		}
		for(int i=ret.size()-1;i>=0;i--) {
			out.print(ret.get(i)+" ");
		}
	}

	private boolean find(List<Integer> l, int m,int[] D,ArrayList<HashSet<Integer>> list) {
		out:
		while(true) {
			for(int i=1;i<=n;i++) {
				if(D[i]==1&&i!=m) {
					l.add(i);
					for(int j=0;j<list.size();j++) {
						HashSet<Integer> s=list.get(j);
						if(s.contains(i)) {
							for(Integer v:s) {
								D[v]--;
							}
							list.remove(j);
							continue out;
						}
					}
				}
			}
			break;
		}
		l.add(m);
		if(l.size()!=n)return false;
		int[] idxs=new int[n+1];
		for(int i=0;i<n;i++) {
			idxs[l.get(i)]=n-i;
		}
		boolean[] vis=new boolean[n+1];
		for(int[] R:rec) {
			int s=n,e=0;
			for(int v:R) {
				s=Math.min(s, idxs[v]);
				e=Math.max(e, idxs[v]);
			}
			if(e-s+1!=R.length)return false;
			vis[e]=true;
		}
		for(int i=2;i<=n;i++) {
			if(!vis[i])return false;
		}
		return true;
	}

	//input
	@SuppressWarnings("unused")
	private ArrayList<Integer>[] ng(int n, int m) {
		ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			int s=in.nextInt()-1,e=in.nextInt()-1;
			graph[s].add(e);
			graph[e].add(s);
		}
		return graph;
	}

	private ArrayList<long[]>[] ngw(int n, int m) {
		ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
			graph[(int)s].add(new long[] {e,w,i});
			graph[(int)e].add(new long[] {s,w});
		}
		return graph;
	}

	private int ni() {
		return in.nextInt();
	}

	private long nl() {
		return in.nextLong();
	}
	
	private String ns() {
		return in.next();
	}

	private long[] na(int n) {
		long[] A=new long[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextLong();
		}
		return A;
	}
	private int[] nia(int n) {
		int[] A=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextInt();
		}
		return A;
	}
}	

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}


	public String next() 
	{
		while(st==null || !st.hasMoreElements())//回车，空行情况
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	public int nextInt() 
	{
		return Integer.parseInt(next());
	}

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}