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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int ans;
        int[] deg;
        int[] col;
        Edge[][] con;
        ArrayList<Edge>[] edg;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int m = in.nextInt();
            edg = new ArrayList[a + b];
            for (int i = 0; i < a + b; ++i) {
                edg[i] = new ArrayList<>();
            }
            deg = new int[a + b];
            for (int i = 0; i < m; ++i) {
                int u = in.nextInt() - 1, v = in.nextInt() - 1;
                edg[u].add(new Edge(v + a, i));
                edg[v + a].add(new Edge(u, i));
                ++deg[u];
                ++deg[v + a];
            }
            ans = 0;
            for (int i = 0; i < a + b; ++i) {
                if (ans < deg[i]) {
                    ans = deg[i];
                }
            }
            con = new Edge[a + b][ans];
            for (int i = 0; i < a + b; ++i) {
                for (int j = 0; j < ans; ++j) {
                    con[i][j] = new Edge(-1, -1);
                }
            }
            col = new int[m];
            Arrays.fill(col, -1);
            for (int i = 0; i < a; ++i) {
                go(i);
            }
            out.println(ans);
            for (int i = 0; i < m; ++i) {
                out.print((col[i] + 1) + (i == m - 1 ? "\n" : " "));
            }
        }

        void go(int u) {
            for (int i = 0; i < edg[u].size(); ++i) {
                int v = edg[u].get(i).to, id = edg[u].get(i).id;
                if (col[id] == -1) {
                    int c = -1, c1 = -1, c2 = -1;
                    for (int j = 0; j < ans; ++j) {
                        if (con[u][j].to == -1) {
                            if (con[v][j].to == -1) {
                                c = j;
                                break;
                            } else {
                                c2 = j;
                            }
                        } else if (con[v][j].to == -1) {
                            c1 = j;
                        }
                    }
                    if (c != -1) {
                        change(u, v, c, id);
                    } else {
                        gao(v, c2, c1);
                        change(u, v, c2, id);
                    }
                }
            }
        }

        void gao(int u, int c1, int c2) {
            int v = con[u][c1].to, id = con[u][c1].id;
            if (con[v][c2].to != -1) {
                gao(v, c2, c1);
            } else {
                con[v][c1].to = -1;
                con[v][c1].id = -1;
            }
            change(u, v, c2, id);
        }

        void change(int u, int v, int c, int id) {
            col[id] = c;
            con[u][c].to = v;
            con[v][c].to = u;
            con[u][c].id = con[v][c].id = id;
        }

        class Edge {
            public int to;
            public int id;

            public Edge(int to, int id) {
                this.to = to;
                this.id = id;
            }

        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            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());
        }

    }
}
