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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 1000;
const int MAXM = 100000;
int nl, nr, m;
int a[MAXM], b[MAXM];
int el[MAXN][MAXN];
int er[MAXN][MAXN];
int res[MAXM];
void run() {
  scanf("%d%d%d", &nl, &nr, &m);
  for (int i = (0); i < (m); ++i) scanf("%d%d", &a[i], &b[i]), --a[i], --b[i];
  memset(el, -1, sizeof(el));
  memset(er, -1, sizeof(er));
  memset(res, -1, sizeof(res));
  for (int i = (0); i < (m); ++i) {
    int ca = 0;
    while (el[a[i]][ca] != -1) ++ca;
    int cb = 0;
    while (er[b[i]][cb] != -1) ++cb;
    for (int x = i, cnt = 0;; ++cnt) {
      int y = er[b[x]][ca];
      el[a[x]][ca] = er[b[x]][ca] = x;
      res[x] = ca;
      if (y == -1) {
        if (x != i) er[b[x]][cb] = -1;
        break;
      }
      int z = el[a[y]][cb];
      el[a[y]][cb] = er[b[y]][cb] = y;
      res[y] = cb;
      if (z == -1) {
        el[a[y]][ca] = -1;
        break;
      }
      x = z;
    }
  }
  int ret = 0;
  for (int i = (0); i < (nl); ++i) {
    int cur = 0;
    for (int j = (0); j < (nr); ++j)
      if (el[i][j] != -1) ++cur;
    if (cur > ret) ret = cur;
  }
  for (int i = (0); i < (nr); ++i) {
    int cur = 0;
    for (int j = (0); j < (nl); ++j)
      if (er[i][j] != -1) ++cur;
    if (cur > ret) ret = cur;
  }
  printf("%d\n", ret);
  for (int i = (0); i < (m); ++i) {
    if (i != 0) printf(" ");
    printf("%d", res[i] + 1);
  }
  puts("");
}
int main() {
  run();
  return 0;
}