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>
void chkmax(T &a, T b) {
  if (a < b) a = b;
}
int n, m, a, b;
int dega[1005], degb[1005];
int ans;
int clr[100005];
int nxta[1005][1005], nxtb[1005][1005];
int uu[100005], vv[100005];
int c1, c2;
int stk[100005], top;
void prep(int v, int side) {
  if (side == 0) {
    int x = v, id = nxta[x][c2];
    if (!id) return;
    int y = vv[id];
    prep(y, 1);
    stk[top++] = id;
  } else {
    int y = v, id = nxtb[y][c1];
    if (!id) return;
    int x = uu[id];
    prep(x, 0);
    stk[top++] = id;
  }
}
int main() {
  scanf("%d %d %d", &a, &b, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &uu[i], &vv[i]);
    dega[uu[i]]++;
    degb[vv[i]]++;
  }
  for (int i = 1; i <= a; i++) chkmax(ans, dega[i]);
  for (int i = 1; i <= b; i++) chkmax(ans, degb[i]);
  for (int i = 1; i <= m; i++) {
    int x = uu[i], y = vv[i];
    int xx = x;
    for (int j = 1; j <= ans && !clr[i]; j++)
      if (!nxta[x][j] && !nxtb[y][j]) {
        clr[i] = j;
        nxta[x][j] = i, nxtb[y][j] = i;
      }
    if (clr[i]) continue;
    c1 = c2 = 0;
    for (int j = 1; j <= ans; j++) {
      if (!nxta[x][j] && nxtb[y][j]) c1 = j;
      if (nxta[x][j] && !nxtb[y][j]) c2 = j;
    }
    top = 0;
    int side = 1, v = y;
    while (1) {
      if (side == 0) {
        int x = v;
        int id = nxta[x][c2];
        if (!id) break;
        stk[top++] = id;
        v = vv[id];
      } else {
        int y = v;
        int id = nxtb[y][c1];
        if (!id) break;
        stk[top++] = id;
        v = uu[id];
      }
      side ^= 1;
    }
    for (int j = 0; j < top; j++) {
      int id = stk[j];
      int oclr = clr[id], nclr = c1 + c2 - oclr;
      int x = uu[id], y = vv[id];
      nxta[x][nclr] = nxtb[y][nclr] = id;
      clr[id] = nclr;
    }
    if (top & 1) {
      int id = stk[top - 1];
      nxta[uu[id]][c1] = 0;
    } else {
      int id = stk[top - 1];
      nxtb[vv[id]][c2] = 0;
    }
    clr[i] = c1;
    nxta[x][c1] = nxtb[y][c1] = i;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= m; i++) printf("%d ", clr[i]);
  return 0;
}