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.*;
import java.lang.*;
public class Main{
    static InputReader sc;
    static PrintWriter pw;
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        sc = new InputReader(inputStream);
        pw = new PrintWriter(outputStream);
        solve();
        pw.close();
    }
    // static int L,R,top,bottom;
    // static int cnt,edge;
    public static void solve() {
        // int t=sc.nextInt();
        int t=1;
        u:while(t-->0){
            int n=s(0);
            int [][]arr=new int[n+1][n+1];
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                    arr[i][j]=s(0);
            List<Integer> prices=new ArrayList<>();
            int[] target=new int[n+1];
            for(int i=1;i<=n;i++){
                prices.add(arr[i][i]);
                target[i]=i;
            }
            PriorityQueue<int[]>pq=new PriorityQueue<>(
                (a,b)->(a[2]==b[2])?((a[0]==b[0])?(a[1]-b[1]):(a[0]-b[0])):(a[2]-b[2]));
            for(int i=1;i<=n;i++)
                for(int j=i+1;j<=n;j++)
                    pq.offer(new int []{i,j,arr[i][j]});
            List<int[]>edges=new ArrayList<>();
            int size=n,r=1;
            int []pr;
            while(size>1&&pq.size()>0){
                pr=pq.poll();
                if(target[pr[0]]==-1||target[pr[1]]==-1)
                    continue;
                // System.out.println(target[pr[0]]+" "+target[pr[1]]+" "+pr[2]);
                if(pr[2]==prices.get(target[pr[0]]-1)){
                    edges.add(new int[]{target[pr[1]],target[pr[0]]});
                    target[pr[1]]=-1;
                    r=target[pr[0]];
                    size--;
                    continue;
                }
                prices.add(pr[2]);
                edges.add(new int[]{target[pr[0]],prices.size()});
                edges.add(new int[]{target[pr[1]],prices.size()});
                target[pr[1]]=-1;
                target[pr[0]]=prices.size();
                r=prices.size();
                size--;
            }
            pw.println(prices.size());
            for(int i:prices)
                pw.print(i+" ");
            pw.println();
            pw.println(r);
            for(int []ar:edges)
                pw.println(ar[0]+" "+ar[1]);
        }
    }
    public static long helper(List<Long> pos, List<Long> box){
        int n=box.size(),m=pos.size();
        long []bip=new long[n];
        int cnt=0;
        int j=m-1;
        for(int i=n-1;i>=0;i--){
            while(j>=0&&pos.get(j)-box.get(i)>0)
                j--;
            if(j>=0&&box.get(i)-pos.get(j)==0)
                cnt++;
            bip[i]=cnt;
        }
        j=0;
        int k=0;
        long max=cnt;
        for(int i=0;i<m;i++){
            while(j<n&&box.get(j)-pos.get(i)<=0)
                j++;
            while(k<m&&pos.get(i)-pos.get(k)-j>=0)
                k++;
            max=Math.max(max,i+1-k+(j==n?0:bip[j]));
        }
        return max;
    }
    public static long func(List<Long> pos, List<Long> box){
        // pln("-------");
        long max=0,val;
        for(int i=0;i<pos.size();i++){
            val=find(box,pos.get(i))+1;
            // pln(pos.get(i)+" "+val);
            val=find(pos,pos.get(i)+val-1l)+1-i;
            // pln(pos.get(i)+" "+val);
            max=Math.max(max,val);
        }
        return max;
    }
    public static int find(List<Long> list, long val){
        int l=0,r=list.size()-1,m;
        while(l<=r){
            m=(r-l)/2+l;
            if(list.get(m)<=val)
                l=m+1;
            else
                r=m-1;
        }
        return r;
    }
    public static boolean isPossible(long u, long v){
        long a,b;
        while(u>0&&v>0){
            a=(u&(-u));
            b=(v&(-v));
            if(b<a)
                return false;
            u-=a;
            v-=b;
        }
        return v==0;
    }
    public static long atMostK(char []chrr, int k){
        if(k<0)
            return 0;
        int l=0,cnt=0;
        long ans=0l;
        for(int i=0;i<chrr.length;i++){
            if(chrr[i]=='1')
                cnt++;
            while(cnt>k){
                if(chrr[l++]=='1')
                    cnt--;
            }
            ans+=(long)(i-l)+1l;
        }
        return ans;
    }
    public static int ask(int l, int r){
        System.out.println("? "+l+" "+r);
        System.out.flush();
        return sc.nextInt();
    }
    public static void sort(long []arr){
        ArrayList<Long> list=new ArrayList<>();
        for(int i=0;i<arr.length;i++)
            list.add(arr[i]);
        Collections.sort(list);
        for(int i=0;i<arr.length;i++)
            arr[i]=list.get(i);
    }
    public static void swap(char []chrr, int i, int j){
        char temp=chrr[i];
        chrr[i]=chrr[j];
        chrr[j]=temp;
    }
    public static int countSetBits(long n){
        int a=0;
        while(n>0){
            a+=(n&1);
            n>>=1;
        }
        return a;
    }
    static class Pair{
        int v;
        String name;
        Pair(int a, String n){
            v=a;
            name=n;
        }
     //*
    }
    /*/
        public int compareTo(Pair p){
            return (b-p.b);
        }
        public int hashCode(){
            int hashcode = (a+" "+b).hashCode();
            return hashcode;
        }
        public boolean equals(Object obj){
            if (obj instanceof Pair) {
                Pair p = (Pair) obj;
                return (p.a==this.a && p.b == this.b);
            }
            return false;
        }
    }
    //*/
    static boolean isPrime(int n) { 
        if (n <= 1) 
            return false; 
        if (n <= 3) 
            return true; 
        if (n % 2 == 0 || n % 3 == 0) 
            return false; 
        for (int i = 5; i * i <= n; i = i + 6) 
            if (n % i == 0 || n % (i + 2) == 0) 
                return false; 
        return true; 
    } 
    static long gcd(long a, long b) { 
        if (b == 0) 
            return a; 
        return a>b?gcd(b, a % b):gcd(a, b % a);  
    } 
    static long fast_pow(long base,long n,long M){
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }
    static long modInverse(long n,long M){
        return fast_pow(n,M-2,M);
    }
    public static int s(int n){
        return sc.nextInt();
    }
    public static long s(long n){
        return sc.nextLong();
    }
    public static String s(String n){
        return sc.next();
    }
    public static double s(double n){
        return sc.nextDouble();
    }
    public static void p(int n){
        pw.print(n);
    }
    public static void p(long n){
        pw.print(n);
    }
    public static void p(String n){
        pw.print(n);
    }
    public static void p(double n){
        pw.print(n);
    }
    public static void pln(int n){
        pw.println(n);
    }
    public static void pln(long n){
        pw.println(n);
    }
    public static void pln(String n){
        pw.println(n);
    }
    public static void pln(double n){
        pw.println(n);
    }
    public static void feedArr(long []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.nextLong();
    }
    public static void feedArr(double []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.nextDouble();
    }
    public static void feedArr(int []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.nextInt();
    }
    public static void feedArr(String []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.next();
    }
    public static String printArr(int []arr){
        StringBuilder sbr=new StringBuilder();
        for(int i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    public  static String printArr(long []arr){
        StringBuilder sbr=new StringBuilder();
        for(long i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    public static String printArr(String []arr){
        StringBuilder sbr=new StringBuilder();
        for(String i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    public static String printArr(double []arr){
        StringBuilder sbr=new StringBuilder();
        for(double i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}