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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, m, k, t[200005], a[1005][5], g, nx[200005], te, t1, t2, c, d[200005],
    d1[2005][1005], p1[2005], p2[2005][1005], h[2005], ans;
struct node {
  int x, y;
} d2[2005], d4[2005][1005];
void add() {
  te++;
  d[te] = t1, t[te] = t2, nx[te] = h[t1];
  h[t1] = te;
  return;
}
inline bool cmp(node x, node y) { return x.y > y.y; }
int main() {
  scanf("%d%d%d", &n, &m, &k);
  memset(h, 0, sizeof(h));
  te = 0;
  memset(a, 0, sizeof(a));
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &t1, &t2);
    a[t1][1]++, a[t2][2]++;
    if (a[t1][1] > a[c][1] && a[t1][1] > a[c][2]) {
      c = t1;
    }
    if (a[t2][2] > a[c][1] && a[t2][2] > a[c][2]) {
      c = t2;
    }
    t2 += n;
    add();
  }
  c = max(a[c][1], a[c][2]);
  printf("%d\n", c);
  memset(d1, 0, sizeof(d1));
  for (int j = 1; j <= k; j++) {
    int i = d[j], l = t[j], x1, x2;
    for (int p = 1; p <= c; p++) {
      if (d1[i][p] == 0) {
        x1 = p;
        break;
      }
    }
    for (int p = 1; p <= c; p++) {
      if (d1[l][p] == 0) {
        x2 = p;
        break;
      }
    }
    d1[i][x1] = l, d1[l][x2] = i;
    if (x1 == x2) continue;
    for (int y = x2, z = l; z; z = d1[z][y], y ^= (x1 ^ x2)) {
      swap(d1[z][x1], d1[z][x2]);
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= c; j++) {
      if (d1[d[i]][j] == t[i]) {
        printf("%d ", j);
        break;
      }
    }
  }
  return 0;
}