Problem: You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour.

Input

The first line contains three integers a, b, m (1 ≤ a, b ≤ 1000, 0 ≤ m ≤ 105), a is the size of the first part, b is the size of the second part, m is the number of edges in the graph.

Each of the next m lines contains two integers x, y (1 ≤ x ≤ a, 1 ≤ y ≤ b), where x is the number of the vertex in the first part and y is the number of the vertex in the second part. It is guaranteed that there are no multiple edges.

Output

In the first line print integer c — the minimal number of colours. The second line should contain m integers from 1 to c — the colours of the edges (in the order they appear in the input).

If there are several solutions, you can print any one of them.

Examples

Input

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


Output

3
1 2 3 1 2

Solution (in JAVA):

Solution:
/**
 * ******* Created on 12/11/19 4:40 AM*******
 */

import java.io.*;
import java.util.*;

public class F600 implements Runnable {

    private static final int MAX = (int) 1e5 + 10;
    private static final int MOD = (int) 1e9 + 7;
    private int a,b;
    private void solve() throws IOException {
        int t = 1;
        while (t-- > 0) {
             a = reader.nextInt();
             b = reader.nextInt();
            int m = reader.nextInt();
            int[] degf = new int[1005];
            int[] degs = new int[1005];
            List<Integer>to = new ArrayList<>();
            List<Integer>from = new ArrayList<>();

            for(int i=0;i<1005;i++) {
                degf[i]=0;
                degs[i]=0;
            }
            int ans =0;

            for(int i=0;i<m;i++){
                int x = reader.nextInt();
                int y = reader.nextInt();
                degf[x]++;
                degs[y]++;
                to.add(x);
                from.add(y);
                ans = Math.max(ans, Math.max(degf[x],degs[y]));
            }
            for(int i=0;i<to.size();i++){
                addEdge(to.get(i), from.get(i),ans);
            }
            writer.println(ans);

            for(int i=0;i<to.size();i++)
                writer.print(aAr[to.get(i)][from.get(i)] +" ");
        }
    }
    boolean[][] ca = new boolean[1005][1005];
    boolean[][] cb = new boolean[1005][1005];
    int[][] aAr = new int[1005][1005];
    int[][] bAr =  new int[1005][1005];
    boolean[] va = new boolean[1005];
    boolean[] vb = new boolean[1005];

    private void addEdge(int p, int q,int ans) {
        for(int i=1 ;i<= ans;i++ ){
            if(ca[p][i] == false && cb[q][i]==false){
                ca[p][i]=true;
                cb[q][i]=true;
                aAr[p][q]=i;
                bAr[q][p]=i;
                return;
            }
        }
        int c1 =0, c2=0;
        for(int i=1;i<=ans;i++){
            if(ca[p][i] ==true && cb[q][i]==false)
                c1=i;
            if(ca[p][i]==false && cb[q][i]==true)
                c2=i;
        }
        aAr[p][q]=c2;
        bAr[q][p]=c2;
        ca[p][c2]=true;
        cb[q][c2]=true;
        Arrays.fill(va, false);
        Arrays.fill(vb, false);
        va[p]=true;
        adjust(q,1, c2, c1);
    }

    private void adjust(int node, int side, int c1, int c2) {
        if(side ==0){
            va[node]=true;
            for(int i=1;i<=b;i++){
                if(vb[i])continue;
                if(aAr[node][i] == c1){
                    aAr[node][i]=c2;
                    bAr[i][node]=c2;
                    cb[i][c1]=false;
                    cb[i][c2]=true;
                    ca[node][c2]=true;
                    adjust(i, side^1, c2,c1);
                    break;
                }
            }
        }else{
            vb[node]=true;
            for(int i=1;i<=a;i++){
                if(va[i])continue;
                if(bAr[node][i] == c1){
                    bAr[node][i] = c2;
                    aAr[i][node] = c2;
                    cb[node][c2] =true;
                    ca[i][c2]=true;
                    ca[i][c1]=false;
                    adjust(i, side^1 , c2,c1);
                    break;
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new F600().run();
        }
    }

    StandardInput reader;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

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

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

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}