The Dogeforces company has k employees. Each employee, except for lower-level employees, has at least 2 subordinates. Lower-level employees have no subordinates. Each employee, except for the head of the company, has exactly one direct supervisor. The head of the company is a direct or indirect supervisor of all employees. It is known that in Dogeforces, each supervisor receives a salary strictly more than all his subordinates.

The full structure of the company is a secret, but you know the number of lower-level employees and for each pair of lower-level employees, the salary of their common supervisor is known (if there are several such supervisors, then the supervisor with the minimum salary). You have to restore the structure of the company.

Input

The first line contains a single integer n (2 ≤ n ≤ 500) — the number of lower-level employees.

This is followed by n lines, where i-th line contains n integers a_{i,1}, a_{i,2}, ..., a_{i,n} (1 ≤ a_{i,j} ≤ 5000) — salary of the common supervisor of employees with numbers i and j. It is guaranteed that a_{i,j} = a_{j,i}. Note that a_{i,i} is equal to the salary of the i-th employee.

Output

In the first line, print a single integer k — the number of employees in the company.

In the second line, print k integers c_1, c_2, ..., c_k, where c_i is the salary of the employee with the number i.

In the third line, print a single integer r — the number of the employee who is the head of the company.

In the following k-1 lines, print two integers v and u (1 ≤ v, u ≤ k) — the number of the employee and his direct supervisor.

Note that the lower-level employees have numbers from 1 to n, and for the rest of the employees, you have to assign numbers from n+1 to k. If there are several correct company structures, you can print any of them.

Example

Input


3
2 5 7
5 1 7
7 7 4


Output


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

Note

One of the possible structures in the first example: <image>
import java.io.*;
import java.util.*;

public class MainD {

    static int N;
    static int[][] A;

    public static void main(String[] args) {
        var sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = new int[N][];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextIntArray(N);
        }

        PrintWriter pw = new PrintWriter(System.out);
        solve(pw);
        pw.flush();
    }

    static int idSeed;

    static void solve(PrintWriter pw) {
        var nodes = new ArrayList<Node>();
        var leafs = new ArrayList<Leaf>();
        for (int i = 0; i < N; i++) {
            var leaf = createLeaf(i);
            leafs.add( leaf );
            nodes.add( new Node(i, leaf.path.peekFirst()) );
        }

        idSeed = N;
        // rootを確定し再帰的に処理する
        // 一番給料の高いやつがrootでどのパスにも存在する
        Node root = new Node(idSeed++, leafs.get(0).path.peekLast());
        for (int i = 0; i < N; i++) {
            leafs.get(i).path.pollLast();
        }
        nodes.add(root);
        calc(root, nodes, leafs);

        pw.println(nodes.size());
        for (int i = 0; i < nodes.size(); i++) {
            if( i != 0 ) pw.print(" ");
            pw.print(nodes.get(i).salary);
        }
        pw.println();

        for (Node node : nodes) {
            if( node.parent == -1 ) {
                pw.println(node.id+1);
            }
        }

        for (Node node : nodes) {
            if( node.parent == -1 ) continue;

            pw.println( (node.id+1) + " " + (node.parent+1));
        }
    }

    static void calc(Node boss, List<Node> nodes, List<Leaf> leafs) {
        var uf = new UnionFind(N);
        var reLeafs = new ArrayList<Leaf>();
        for (Leaf leaf : leafs) {
            int salary = leaf.path.peekLast();
            if( leaf.path.size() == 1 ) {
                // mine
                nodes.get(leaf.id).parent = boss.id;

            } else {
                // boss
                for (int i = 0; i < N; i++) {
                    if( A[leaf.id][i] == salary ) {
                        uf.unite(leaf.id, i);
                    }
                }
                reLeafs.add(leaf);
            }
        }
        leafs = reLeafs;

        var groups = new HashMap<Integer, List<Leaf>>();

        for (Leaf leaf : leafs) {
            var group = uf.root(leaf.id);
            if( !groups.containsKey(group) ) {
                groups.put(group, new ArrayList<>());
            }
            groups.get(group).add(leaf);
        }

        for (List<Leaf> group : groups.values()) {
            int salary = group.get(0).path.peekLast();
            for (Leaf leaf : group) {
                leaf.path.pollLast();
            }
            Node groupBoss = new Node(idSeed++, salary);
            groupBoss.parent = boss.id;
            nodes.add(groupBoss);
            calc(groupBoss, nodes, group);
        }
    }

    static class UnionFind {

        private final int[] parent;
        private final int[] count;

        public UnionFind(int n) {
            parent = new int[n];
            count = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
                count[i] = 1;
            }
        }

        public int root(int i) {
            if( parent[i] == i ) {
                return i;
            } else {
                return parent[i] = root(parent[i]);
            }
        }

        public int unite(int i, int j) {
            int ri = root(i);
            int rj = root(j);
            if( ri == rj ) return ri;


            int big = count[ri] < count[rj] ? rj : ri;
            int small = big == ri ? rj : ri;
            parent[small] = big;
            count[big] += count[small];
            return big;
        }

        public int count(int a) {
            return count[root(a)];
        }

        public boolean isSame(int a, int b) {
            return root(a) == root(b);
        }
    }

    static class Leaf {
        final int id;
        final ArrayDeque<Integer> path;

        public Leaf(int id, ArrayDeque<Integer> path) {
            this.id = id;
            this.path = path;
        }
    }

    static Leaf createLeaf(int id) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < N; i++) {
            set.add( A[id][i] );
        }
        List<Integer> path = new ArrayList<>(set);
        path.sort(Comparator.naturalOrder());
        return new Leaf(id, new ArrayDeque<>(path));
    }

    static class Node {
        final int id;
        final int salary;
        int parent = -1;

        public Node(int id, int salary) {
            this.id = id;
            this.salary = salary;
        }
    }

    static void calc(List<Integer> leafs) {
        int max = 0;
        for (Integer leaf : leafs) {
            max = Math.max(0, A[leafs.get(0)][leaf]);
        }


    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

        int[] nextIntArray(int n) {
            var a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        int[] nextIntArray(int n, int delta) {
            var a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt() + delta;
            return a;
        }

        long[] nextLongArray(int n) {
            var a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }

    static void writeLines(int[] as) {
        var pw = new PrintWriter(System.out);
        for (var a : as) pw.println(a);
        pw.flush();
    }

    static void writeLines(long[] as) {
        var pw = new PrintWriter(System.out);
        for (var a : as) pw.println(a);
        pw.flush();
    }

    static void writeSingleLine(int[] as) {
        var pw = new PrintWriter(System.out);
        for (var i = 0; i < as.length; i++) {
            if (i != 0) pw.print(" ");
            pw.print(as[i]);
        }
        pw.println();
        pw.flush();
    }

    static void debug(Object... args) {
        var j = new StringJoiner(" ");
        for (var arg : args) {
            if (arg == null) j.add("null");
            else if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));
            else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));
            else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));
            else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));
            else j.add(arg.toString());
        }
        System.err.println(j.toString());
    }
}
