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
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
		if (new File("input.txt").exists())
			in = new BufferedReader(new FileReader("input.txt"));
		else
			in = new BufferedReader(new InputStreamReader(System.in));
		if (new File("output.txt").exists())
			out = new PrintWriter("output.txt");
		else
			out = new PrintWriter(System.out);
	    
//        in = new BufferedReader(new FileReader("input.txt"));
//        out = new PrintWriter(System.out);
	    
//        in = new BufferedReader(new FileReader("input.txt"));
//        out = new PrintWriter("output.txt");
		
		solve();
		
		in.close();
		out.close();
	}
	
	final int MAX_N = 2015;
	final int MAX_M = 2 * 100 * 1000 + 100;
	
	int a, b;
	int n, m;
	Edge edges[] = new Edge[MAX_M];
	
	int delta = 0;
	int degree[] = new int[MAX_N];
	int g[][] = new int[MAX_N][MAX_N];
	int next[][] = new int[MAX_N][MAX_N];
	int color[][] = new int[MAX_N][MAX_N];
	
	
	void solve() throws IOException {
	    a = nextInt();
	    b = nextInt();
	    n = a + b;
	    m = nextInt();
	    for (int i = 0; i < m; ++i) {
	        int u = nextInt() - 1;
	        int v = a + nextInt() - 1;
	        g[u][v] = g[v][u] = 1;
	        degree[u]++;
	        degree[v]++;
	        delta = max(delta, degree[u]);
	        delta = max(delta, degree[v]);
	        edges[i] = new Edge(u, v);
	    }
	    for (int i = 0; i < n; ++i) { 
	        fill(next[i], 0, n, -1);
	        fill(color[i], 0, n, -1);
	    }

	    for (int e = 0; e < m; ++e) {
	        Edge edge = edges[e];
	        int u = edge.u, v = edge.v;
	        int c = -1, cu = -1, cv = -1;
	        for (int i = 0; i < delta; ++i) {
	            if (next[i][u] == -1 && next[i][v] == -1) {
	                c = i;
	                break;
	            }
	            if (next[i][u] != -1 && next[i][v] == -1) {
                    cu = i;
                }
	            if (next[i][u] == -1 && next[i][v] != -1) {
                    cv = i;
                }
	        }
	        
//	        if (e == 7)
//	            System.err.println(next[2][4]);
	        
	        if (c != -1) {
	            next[c][u] = v;
	            next[c][v] = u;
	            color[u][v] = color[v][u] = c;
	        } else {
	            
//	            System.err.println(e);
//	            System.err.println(u + " " + v);
//                for (int i = 0; i < m; ++i)
//                    System.err.println(color[edges[i].u][edges[i].v] + " ");
//                System.err.println("cu = " + cu + ", cv = " + cv);
	            
	            while (v != -1) {
                    int to = next[cv][v];
                    next[cv][u] = v;
                    next[cv][v] = u;
                    color[u][v] = color[v][u] = cv;
                    u = v;
                    v = to;
                    int swap = cu; cu = cv; cv = swap;
	            }
	            next[cv][u] = -1;
	            
//	            System.err.println();
	        }
	    }
	    
	    out.println(delta);
	    for (int i = 0; i < m; ++i)
	        out.print((color[edges[i].u][edges[i].v] + 1) + " ");
	    out.println();
	}
	
	class Edge {
	    final int u, v;

        public Edge(int u, int v) {
            super();
            this.u = u;
            this.v = v;
        }
	    
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

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

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

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

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String str = in.readLine();
			if (str == null)
				return true;
			st = new StringTokenizer(str);
		}
		return false;
	}

}
