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;
struct edge {
  int a, b;
};
int n1, n2, m, c;
int deg1[1000 + 1], deg2[1000 + 1];
int adj[1000 + 1][1000 + 1], adjc[1000 + 1][1000 + 1];
int adjcv1[1000 + 1][1000 + 1], adjcv2[1000 + 1][1000 + 1];
edge e[100000];
void change1(int x, int from, int to);
void change2(int x, int from, int to);
void change1(int x, int from, int to) {
  int flag = 0;
  if (adjcv2[adjcv1[x][from]][to])
    change2(adjcv1[x][from], to, from);
  else
    flag = 1;
  adjc[x][adjcv1[x][from]] = to;
  adjcv1[x][to] = adjcv1[x][from];
  adjcv2[adjcv1[x][to]][to] = x;
  if (flag) adjcv2[adjcv1[x][from]][from] = 0;
  adjcv1[x][from] = 0;
}
void change2(int x, int from, int to) {
  int flag = 0;
  if (adjcv1[adjcv2[x][from]][to])
    change1(adjcv2[x][from], to, from);
  else
    flag = 1;
  adjc[adjcv2[x][from]][x] = to;
  adjcv2[x][to] = adjcv2[x][from];
  adjcv1[adjcv2[x][to]][to] = x;
  if (flag) adjcv1[adjcv2[x][from]][from] = 0;
  adjcv2[x][from] = 0;
}
void solve(int n1, int n2) {
  if (n1 == 0) return;
  solve(n1 - 1, n2);
  for (int i = 1, cn = 1; i <= n2; ++i) {
    if (adj[n1][i]) {
      if (adjcv2[i][cn]) {
        for (int j = 1; j <= c; ++j) {
          if (adjcv2[i][j] == 0) {
            change2(i, cn, j);
            break;
          }
        }
      }
      adjcv1[n1][cn] = i;
      adjcv2[i][cn] = n1;
      adjc[n1][i] = cn++;
    }
  }
}
int main() {
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = 0; i < m; ++i) scanf("%d%d", &e[i].a, &e[i].b);
  for (int i = 0; i < m; ++i) {
    adj[e[i].a][e[i].b] = 1;
    deg1[e[i].a]++;
    deg2[e[i].b]++;
  }
  for (int i = 1; i <= n1; ++i) c = max(c, deg1[i]);
  for (int i = 1; i <= n1; ++i) c = max(c, deg2[i]);
  solve(n1, n2);
  printf("%d\n", c);
  for (int i = 0; i < m; ++i) printf("%d ", adjc[e[i].a][e[i].b]);
  return 0;
}