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;
inline int re_ad() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}
int a, b, m;
int rd[2010], ans;
int col[2010][2010];
struct node {
  int u, v;
} e[100010];
int main() {
  register int i, j, x, y;
  register int co[2], now;
  a = re_ad();
  b = re_ad();
  m = re_ad();
  for (i = 1; i <= m; ++i) {
    e[i].u = x = re_ad();
    e[i].v = y = re_ad() + a;
    ++rd[x];
    ++rd[y];
  }
  for (i = 1; i <= a + b; ++i) ans = max(ans, rd[i]);
  for (i = 1; i <= m; ++i) {
    for (j = 1; j <= ans; ++j)
      if (!col[e[i].u][j]) {
        co[0] = j;
        break;
      }
    for (j = 1; j <= ans; ++j)
      if (!col[e[i].v][j]) {
        co[1] = j;
        break;
      }
    col[e[i].u][co[0]] = e[i].v;
    col[e[i].v][co[1]] = e[i].u;
    if (co[0] == co[1]) continue;
    now = 1;
    x = e[i].v;
    while (x) {
      swap(col[x][co[1]], col[x][co[0]]);
      x = col[x][co[now]];
      now ^= 1;
    }
  }
  printf("%d\n", ans);
  for (i = 1; i <= m; ++i) {
    for (j = 1; j <= ans; ++j) {
      if (col[e[i].u][j] == e[i].v) {
        printf("%d ", j);
        break;
      }
    }
  }
}