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.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            FEdgeColoringOfBipartiteGraph solver = new FEdgeColoringOfBipartiteGraph();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class FEdgeColoringOfBipartiteGraph {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int a = in.readInt();
            int b = in.readInt();
            int m = in.readInt();

            Node[] nodes = new Node[a + b];
            for (int i = 0; i < a + b; i++) {
                nodes[i] = new Node();
                nodes[i].id = i < a ? i : -(i - a);
            }

            Edge[] edges = new Edge[m];
            for (int i = 0; i < m; i++) {
                edges[i] = new Edge();
                edges[i].a = nodes[in.readInt() - 1];
                edges[i].b = nodes[a + in.readInt() - 1];
                edges[i].a.deg++;
                edges[i].b.deg++;
            }

            int maxDeg = 0;
            for (Node node : nodes) {
                maxDeg = Math.max(maxDeg, node.deg);
            }

            for (Node node : nodes) {
                node.colored = new Edge[maxDeg];
            }

            for (Edge e : edges) {

                int color = -1;
                int c1 = -1;
                int c2 = -1;
                for (int i = 0; i < maxDeg; i++) {
                    if (e.a.colored[i] == null && e.b.colored[i] == null) {
                        color = i;
                        break;
                    }
                    if (e.a.colored[i] == null) {
                        c2 = i;
                    }
                    if (e.b.colored[i] == null) {
                        c1 = i;
                    }
                }
                if (color != -1) {
                    e.setColor(color);
                    continue;
                }
                if (c1 == c2) {
                    throw new IllegalArgumentException();
                }
                replace(e.b, c2, c1);
                e.setColor(c2);
            }

            out.println(maxDeg);
            for (Edge e : edges) {
                out.append(e.c + 1).append(' ');
            }
        }

        public void replace(Node root, int c1, int c2) {
            if (root.colored[c1] == null) {
                return;
            }
            Edge e = root.colored[c1];
            Node node = e.other(root);
            replace(node, c2, c1);
            e.setColor(c2);
        }

    }

    static class Edge {
        Node a;
        Node b;
        int c = -1;

        Node other(Node x) {
            return a == x ? b : a;
        }

        void setColor(int c) {
            if (this.c != -1) {
                if (a.colored[this.c] == this) {
                    a.colored[this.c] = null;
                }
                if (b.colored[this.c] == this) {
                    b.colored[this.c] = null;
                }
            }
            this.c = c;
            a.colored[c] = b.colored[c] = this;
        }

        public String toString() {
            return a + "->" + b;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class Node {
        int deg;
        Edge[] colored;
        int id;

        public String toString() {
            return "" + id;
        }

    }
}

