Problem: Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.

Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i is strictly greater than the value at position j.

Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the n arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most <image> (at most <image> pairs). Help Iahub, find any suitable array.

Input

The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each element x of the array i, 1 ≤ x ≤ 106 holds.

Output

On the first line of the output print an integer p, the size of the array (p can be at most <image>). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices.

If there are multiple correct answers, you can print any.

Examples

Input

2 5 0
1 3 2 5 4
1 4 3 2 5


Output

3
2 4
2 3
4 5


Input

3 2 1
1 2
2 3
3 4


Output

1
2 1

Note

Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].

Solution (in JAVA):

Solution:
import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;


public class Solution{
    
    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;
        
        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }
        
        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }
        
        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }
        
/*      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
*/      
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }
        
        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }
            
        }
        public String readLine() throws IOException{
            return s.readLine();
        }
        
        public void close() throws IOException{
            s.close();
        }
        
    }
    
    ////////////////////////////////////////////////////////////////////
    //      Number Theory
    
    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;         
        }
        return x;
    }
    
    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }
    
    void findSubsets(int array[]){
        
        long numOfSubsets = 1 << array.length; 
        for(int i = 0; i < numOfSubsets; i++){
                
            int pos = array.length - 1;
            int bitmask = i;

            while(bitmask > 0){     
                if((bitmask & 1) == 1)
                    ww.print(array[pos]+" ");
                
                bitmask >>= 1;
                pos--;
            }

            ww.println();
        }
    }
    
    
    public static long gcd(long a, long b){
        return b == 0 ? a : gcd(b,a%b);
    }
    
  
    public static int lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }
    
    public static int lcm(int a, int b){
        return (int) (a*b/gcd(a,b));
    }
    
    ////////////////////////////////////////////////////////////////////
    
    
//    private static    FastScanner s = new FastScanner(new File("input.txt"));
//    private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    static InputStream inputStream = System.in;
    static FastScanner s = new FastScanner(inputStream); 
    static OutputStream outputStream = System.out;
    static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };
    
      
    //////////////////////////////////////////////////////////////////// 
      
     
    public static void main(String[] args) throws IOException{
        new Solution().solve();
        s.close();
        ww.close();
    }
    
    
    ////////////////////////////////////////////////////////////////////
    
    int cons = 100000000;
    Set<Integer> st = new HashSet<Integer>();
    ArrayDeque<Point> arr = new ArrayDeque<Point>();
    int count = 0;
    int n; int m; int o;
    
    int min(int[] a, int x){
        int min = Integer.MAX_VALUE;
        int index = -1;
        for(int i=x;i<a.length;i++){
            min = Math.min(min, a[i]);
            if(min == a[i]) index = i;
        }
        return index;
    }
    
    int max(int[] a, int x){
        int max = Integer.MIN_VALUE;
        int index = -1;
        for(int i=x;i<a.length;i++){
            max = Math.max(max, a[i]);
            if(max == a[i]) index = i;
        }
        return index;
    }
    
    void asc(int[][] a,int bo){
        
        for(int i=0;i<a[0].length;i++){
            int min = min(a[bo],i);
            if(min == i || min == -1 || a[bo][min] == a[bo][i]) continue;
            arr.add(new Point(i+1,min+1));
            for(int k=bo;k<a.length;k++){
                if(a[k][i] < a[k][min]) continue;
                int sw = a[k][i];
                a[k][i] = a[k][min];
                a[k][min] = sw;
            }
        }
        
    }
    
    void dsc(int[][] a,int bo){
        
        for(int i=0;i<a[0].length;i++){
            int max = max(a[bo],i);
            if(max == i || max == -1 || a[bo][max] == a[bo][i]) continue;
            arr.add(new Point(max+1,i+1));
            for(int k=bo;k<a.length;k++){
                if(a[k][i] > a[k][max]) continue;
                int sw = a[k][i];
                a[k][i] = a[k][max];
                a[k][max] = sw;
            }
        }
        
    }
    
    void solve() throws IOException{
        
        n = s.nextInt();
        m = s.nextInt();
        o = s.nextInt();
        int[][] a = new int[n][m];
        for(int j=0;j<n;j++){
            int[] x = new int[m];
            for(int i=0;i<m;i++) x[i] = s.nextInt();
            a[j] = x;
        }
        for(int i=0;i<n;i++){
//          for(int x : a[i]) ww.print(x+" ");
//          ww.println();
            if(o == 0)
                asc(a,i);
            else dsc(a,i);
        }
        
        ww.println(arr.size());
        while(!arr.isEmpty()){
            Point xm = arr.pollFirst();
            ww.println(xm.x+" "+xm.y);
        }
        
    }
}