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;
template <class t>
inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 2005, M = 1e5 + 5;
int n, nn, m, a[M], b[M], du[N], lnk[N][N], mx;
signed main() {
  read(n);
  read(nn);
  read(m);
  for (int i = 1; i <= m; i++) {
    read(a[i]);
    read(b[i]);
    b[i] += n;
    du[a[i]]++;
    du[b[i]]++;
  }
  mx = *max_element(du + 1, du + 1 + n + nn);
  for (int i = 1; i <= m; i++) {
    int p = 1, q = 1;
    while (lnk[a[i]][p]) p++;
    while (lnk[b[i]][q]) q++;
    lnk[a[i]][p] = b[i];
    lnk[b[i]][q] = a[i];
    if (p == q) continue;
    for (int c = q, x = b[i]; x; x = lnk[x][c], c ^= p ^ q)
      swap(lnk[x][p], lnk[x][q]);
  }
  write(mx);
  puts("");
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= mx; j++)
      if (lnk[a[i]][j] == b[i]) {
        write(j);
        putchar(' ');
        break;
      }
}