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.*;
    import java.util.*;
    import java.math.*;
    import java.lang.*;

    import static java.lang.Math.*;

    public class Main implements Runnable
    {
        static class InputReader
        {
            private InputStream stream;
            private byte[] buf = new byte[1024];
            private int curChar;
            private int numChars;
            private SpaceCharFilter filter;
            private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

            public InputReader(InputStream stream)
            {
                this.stream = stream;
            }

            public int read()
            {
                if (numChars==-1)
                    throw new InputMismatchException();

                if (curChar >= numChars)
                {
                    curChar = 0;
                    try
                    {
                        numChars = stream.read(buf);
                    }
                    catch (IOException e)
                    {
                        throw new InputMismatchException();
                    }

                    if(numChars <= 0)
                        return -1;
                }
                return buf[curChar++];
            }

            public String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                return str;
            }
            public int nextInt()
            {
                int c = read();

                while(isSpaceChar(c))
                    c = read();

                int sgn = 1;

                if (c == '-')
                {
                    sgn = -1;
                    c = read();
                }

                int res = 0;
                do
                {
                    if(c<'0'||c>'9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = read();
                }
                while (!isSpaceChar(c));

                return res * sgn;
            }

            public long nextLong()
            {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                int sgn = 1;
                if (c == '-')
                {
                    sgn = -1;
                    c = read();
                }
                long res = 0;

                do
                {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = read();
                }
                while (!isSpaceChar(c));
                    return res * sgn;
            }

            public double nextDouble()
            {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                int sgn = 1;
                if (c == '-')
                {
                    sgn = -1;
                    c = read();
                }
                double res = 0;
                while (!isSpaceChar(c) && c != '.')
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = read();
                }
                if (c == '.')
                {
                    c = read();
                    double m = 1;
                    while (!isSpaceChar(c))
                    {
                        if (c == 'e' || c == 'E')
                            return res * Math.pow(10, nextInt());
                        if (c < '0' || c > '9')
                            throw new InputMismatchException();
                        m /= 10;
                        res += (c - '0') * m;
                        c = read();
                    }
                }
                return res * sgn;
            }

            public String readString()
            {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                StringBuilder res = new StringBuilder();
                do
                {
                    res.appendCodePoint(c);
                    c = read();
                }
                while (!isSpaceChar(c));

                return res.toString();
            }

            public boolean isSpaceChar(int c)
            {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

            public String next()
            {
                return readString();
            }

            public interface SpaceCharFilter
            {
                public boolean isSpaceChar(int ch);
            }
        }


        public static void main(String args[]) throws Exception
        {
            new Thread(null, new Main(),"Main",1<<26).start();
        }
        //User-defined functions goes here...
        class pair{
            int x, y;
            pair(int x, int y){
                this.x = x;
                this.y = y;
            }
        }

      
        void swap(int[] a, int pos1, int pos2){
            int temp = a[pos1];
            a[pos1] = a[pos2];
            a[pos2] = temp;
        }


        boolean powerof2(int n){
            return ((n > 2) && ((n & (n-1)) == 0));
        }


        void bfs(int st, int[] dist){
            Queue<Integer> q = new LinkedList<>();
            dist[st] = 0;
            q.add(st);

            while(q.size()>0){
                int temp = q.poll();
                for (int i: graph[temp]) {
                    if(dist[i] == Integer.MAX_VALUE){
                        q.add(i);
                        dist[i] = dist[temp] + 1;
                    }
                }
            }
        }

        ArrayList<Integer>[] graph;
        public void run()
        {
            InputReader sc= new InputReader(System.in);
            PrintWriter w= new PrintWriter(System.out);

            //Your code goes here...
            int test = sc.nextInt();
            for (int q0=0; q0<test; q0++) {
                int n = sc.nextInt();
                ArrayList<HashSet<Integer>> segs = new ArrayList<>();

                for (int i=0; i<n-1; i++) {
                    int k = sc.nextInt();
                    HashSet<Integer> temp = new HashSet<>();
                    for (int j=0; j<k; j++) {
                        temp.add(sc.nextInt());
                    }
                    segs.add(temp);                    
                }


                ArrayList<Integer> ans = new ArrayList<>();
                for (int fst=1; fst<=n; fst++) {
                    boolean ok = true;
                    ArrayList<HashSet<Integer>> curr = new ArrayList<HashSet<Integer>>();
                    for(HashSet<Integer> tt: segs){
                        curr.add((HashSet)tt.clone());
                    }
                    ans.clear();
                    for (int i=0; i<curr.size(); i++) {
                        if(curr.get(i).contains(fst)){
                            curr.get(i).remove(fst);
                        }
                    }
                    ans.add(fst);

                    for (int i=1; i<n; i++) {
                       int nxt = -1;
                       int cnt = 0;
                       for (int j=0; j<curr.size(); j++) {
                            if(curr.get(j).size() == 1){
                                cnt++;
                                nxt = curr.get(j).iterator().next();
                            }      
                        }

                        if(cnt != 1){
                            ok = false;
                            break;
                        }

                        for (int j=0; j<curr.size(); j++) {
                            if(curr.get(j).contains(nxt))
                                curr.get(j).remove(nxt);
                        }

                        ans.add(nxt);               
                    }
                    // w.println("FST: " + fst);
                    // w.println(ok);
                    // w.println(ans);
                    // w.println();


                    if(ok == true){
                        HashSet<HashSet<Integer>> check = new HashSet<HashSet<Integer>>(segs);
                        for(int r=1; r<n; r++){
                            boolean found = false;
                            HashSet<Integer> temp = new HashSet<Integer>();
                            temp.add(ans.get(r));

                            for (int l=r-1; l>=0; l--) {
                                temp.add(ans.get(l));
                                if(check.contains(temp)){
                                    found = true;
                                    check.remove(temp);
                                    break;
                                }
                            }

                            if(found == false){
                                ok = false;
                                break;
                            }
                        }
                    } 

                    if(ok){
                        for (int i=0; i<ans.size(); i++) {
                            w.print(ans.get(i) + " ");
                        }
                        w.println();
                        break;
                    }         
                }                

            }

            w.close();
        }
    }