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;
namespace Stand_IO_Operation {
inline int read() {
  int f = 1, res = 0, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
  return f * res;
}
int _sta[1 << 8];
inline void write(int val) {
  if (!val) {
    putchar('0');
    return;
  }
  if (val < 0) putchar('-'), val = -val;
  *_sta = 0;
  while (val > 0) _sta[++*_sta] = val % 10, val /= 10;
  for (int i = *_sta, _Lim = 1; i >= _Lim; i--) putchar(_sta[i] + 48);
}
};  // namespace Stand_IO_Operation
using namespace Stand_IO_Operation;
const int N = 1005;
const int M = 100005;
int a, b, m, Map[N][N], Dgl[N], Dgr[N], L[N][N], R[N][N], Col[N], Ans;
int main() {
  scanf("%d%d%d", &a, &b, &m);
  for (int i = 1, _Lim = m; i <= _Lim; i++) {
    int x = read(), y = read();
    Map[x][y] = i;
    Dgl[x]++;
    Dgr[y]++;
    Ans = max(Ans, max(Dgl[x], Dgr[y]));
    int cx = 1, cy = 1;
    while (L[x][cx]) cx++;
    while (R[y][cy]) cy++;
    if (cx == cy) {
      L[x][cx] = y, R[y][cy] = x;
      continue;
    }
    L[x][cx] = y;
    while (true) {
      int x_ = R[y][cx];
      R[y][cx] = x;
      R[y][cy] = x_;
      if (!x_) break;
      x = x_;
      int y_ = L[x][cy];
      L[x][cy] = y;
      L[x][cx] = y_;
      if (!y_) break;
      y = y_;
    }
  }
  printf("%d\n", Ans);
  for (int i = 1, _Lim = a; i <= _Lim; i++)
    for (int j = 1, _Lim = Ans; j <= _Lim; j++)
      if (L[i][j]) Col[Map[i][L[i][j]]] = j;
  for (int i = 1, _Lim = m; i <= _Lim; i++) printf("%d ", Col[i]);
  puts("");
}