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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;



public class A
{
	static class Pair
	{
	    int a;
	    int b;
	    Pair(int a,int b)
	    {
	        this.a = a;
	        this.b = b;
	    }
	    public int hashCode(){
	        //System.out.println("In hashcode");
	        int hashcode = 0;
	        hashcode = a*20;
	        hashcode += b*20;
	        return hashcode;
	    }
	     
	    public boolean equals(Object obj){
	        //System.out.println("In equals");
	        if (obj instanceof Pair) {
	            Pair pp = (Pair) obj;
	            return (pp.a == this.a && pp.b == this.b);
	        } else {
	            return false;
	        }
	    
	}
	}
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    static int gcd(int a,int b)
	{
		if(a == 0) return b;
		if(b == 0) return a;
		
		return gcd(b,a%b);
	}
    
    
    
    public static void main(String[] args)
    {
        OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        int t = sc.nextInt();
        while(t-- > 0)
        {
        	int n = sc.nextInt();
        	HashSet<Integer> hs[] = new HashSet[n-1];
        	HashSet<Integer> cs[] = new HashSet[n-1];
        	
        	HashSet<ArrayList<Integer>> hm = new HashSet<>();
        	
        	for(int i = 0; i < n-1; i++)
        	{	
        		ArrayList<Integer> hr = new ArrayList<>();
        		hs[i] = new HashSet<>();
        		cs[i] = new HashSet<>();
        		int k = sc.nextInt();
        		for(int j = 0; j < k; j++)
        		{	
        			int x = sc.nextInt();
        			hs[i].add(x);
        			cs[i].add(x);
        			hr.add(x);
        		}
        		hm.add(hr);
        	}
        	
        	outer: for(int i = 1; i <= n; i++)
        	{	
        		int cnt;
        		
        		int rem = i;
        		int nrem = i;
        		int r = n;
        		
        		ArrayList<Integer> ar = new ArrayList<>();
        		while(r-- > 0)
        		{	
        			rem = nrem;
        			cnt = 0;
        			for(int j = 0; j < n-1; j++)
        			{
        				if(hs[j].size() > 0 && hs[j].contains(rem))
        				{	
        					System.err.println(rem+" "+j+" "+r+" "+i+" "+hs[j].size());
        					hs[j].remove(rem);
        					if(r == 0) cnt = 1;
        					if(hs[j].size() == 1)
        					{
        						cnt++;
        						
        						for(int p:hs[j])
        						{
        							nrem = p;
        						}
        					}
        				}
        			}
        			
        			if(cnt != 1)
        			{
        				for(int j = 0; j < n-1; j++)
        				{
        					hs[j] = (HashSet<Integer>) cs[j].clone();
        				}
        				continue outer;
        			}
        			
        			System.err.println(rem+" "+nrem+" "+r+" "+i);
        			ar.add(rem);
        			
        		}
        		
        		//System.err.println(ar.toString());
        		//check
        		boolean check = false;
        		ArrayList<Integer> br = new ArrayList<>();
        		for(int m = 1; m < n; m++)
        		{	
        			check = false;
        			br = new ArrayList<>();
        			for(int o = m; o >= 0; o--)
        			{
        				br.add(ar.get(o));
        				
        				Collections.sort(br);
            			//System.err.println(br.toString());
            			if(hm.contains(br))
            			{
            				check = true;
            				break;
            			}
        			}
        			if(!check) break;
        			
        		}
        		
        		if(check)
        		{
        			for(int m :ar)
        			{
        				out.print(m+" ");
        			}
        			out.println();
        			break;
        		}
        		else
        		{
        			for(int j = 0; j < n-1; j++)
    				{
    					hs[j] = (HashSet<Integer>) cs[j].clone();
    				}
        		}
        	}
        		
        	
        }
        
        out.close();
    }

}