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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.util.AbstractSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FRestoreThePermutationBySortedSegments solver = new FRestoreThePermutationBySortedSegments();
        solver.solve(1, in, out);
        out.close();
    }

    static class FRestoreThePermutationBySortedSegments {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int t = s.nextInt();
            while (t-- > 0) {
                int n = s.nextInt();
                ArrayList<HashSet<Integer>> list = new ArrayList<>();
                for (int i = 0; i < n - 1; i++) {
                    int size = s.nextInt();
                    HashSet<Integer> set = new HashSet<>();
                    for (int j = 0; j < size; j++) {
                        set.add(s.nextInt());
                    }
                    list.add(set);
                }

                ArrayList<HashSet<Integer>> list1;
                for (int i = 1; i <= n; i++) {
                    list1 = new ArrayList<>();
                    for (int j = 0; j < list.size(); j++) {
                        list1.add(new HashSet<>(list.get(j)));
                    }
                    int currFirst = i;
                    int[] ans = new int[n];
                    for (int j = 0; j < n - 1; j++) {
                        HashSet<Integer> set = list1.get(j);
                        set.remove(currFirst);
                        list1.set(j, set);
                    }

                    int currPos = 1;
                    boolean found = true;
                    ans[0] = currFirst;
                    while (currPos < n) {

                        int count = 0;
                        int currIndex = 0;
                        for (int j = 0; j < n - 1; j++) {
                            if (list1.get(j).size() == 1) {
                                count++;
                                currIndex = j;
                            }
                        }

                        if (count == 1) {
                            ans[currPos] = list1.get(currIndex).iterator().next();
                            for (int j = 0; j < list1.size(); j++) {
                                HashSet<Integer> set = list1.get(j);
                                set.remove(ans[currPos]);
                                list1.set(j, set);
                            }
                            currPos++;
                        } else {
                            found = false;
                            break;
                        }
                    }

                    if (!found) {
                        continue;
                    } else {
                        found = check(ans, list);
                        if (!found) {
                            continue;
                        } else {
                            out.println(FRestoreThePermutationBySortedSegments.arrays.printArr(ans));
                            break;
                        }
                    }


                }
            }
        }

        private boolean check(int[] ans, ArrayList<HashSet<Integer>> list) {

            for (int i = 0; i < list.size(); i++) {
                int size = list.get(i).size();
                HashSet<Integer> set1 = new HashSet<>();
                boolean found = false;
                for (int j = 0; j < size; j++) {
                    set1.add(ans[j]);
                }


                int currStart = 0;
                int currEnd = size;
                while (currEnd <= ans.length) {
                    if (set1.equals(list.get(i))) {
                        found = true;
                        break;
                    } else {
                        if (currEnd == ans.length) {
                            break;
                        }
                        set1.remove(ans[currStart++]);
                        set1.add(ans[currEnd++]);
                    }
                }

                if (!found) {
                    return false;
                }
            }
            return true;
        }

        private static class arrays {
            static String formatString(String str) {
                str = str.replace(",", "").replace("[", "").replace("]", "");
                return str;
            }

            static StringBuilder printArr(Object arr) {
                String str = null;
                if (arr instanceof int[]) {
                    str = Arrays.toString((int[]) arr);
                }

                if (arr instanceof long[]) {
                    str = Arrays.toString((long[]) arr);
                }

                if (arr instanceof char[]) {
                    str = Arrays.toString((char[]) arr);
                }

                if (arr instanceof boolean[]) {
                    str = Arrays.toString((boolean[]) arr);
                }

                if (arr instanceof byte[]) {
                    str = Arrays.toString((byte[]) arr);
                }

                if (arr instanceof double[]) {
                    str = Arrays.toString((double[]) arr);
                }

                if (arr instanceof float[]) {
                    str = Arrays.toString((float[]) arr);
                }

                if (arr instanceof short[]) {
                    str = Arrays.toString((short[]) arr);
                }

                if (str != null) {
                    return new StringBuilder(formatString(str));
                }

                return null;

            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(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 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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}