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;
int n, m, co[2][3000][3000], r1[300000], r2[300000], id[3000][3000],
    res1[3000][3000], d[2][3000];
void dfs(int p, int u, int v, int c1, int c2) {
  int t = co[p ^ 1][v][c1];
  co[p][u][c1] = v;
  co[p ^ 1][v][c1] = u;
  if (!t) {
    co[p ^ 1][v][c2] = 0;
    return;
  }
  dfs(p ^ 1, v, t, c2, c1);
}
int main() {
  int num;
  cin >> n >> m >> num;
  int res = 0;
  int u, v;
  for (int i = 1; i <= num; i++) {
    cin >> u >> v;
    id[u][v] = 1;
    d[0][u]++, d[1][v]++;
    res = max(res, max(d[0][u], d[1][v]));
    r1[i] = u;
    r2[i] = v;
  }
  for (int i = 1; i <= num; i++) {
    int u = r1[i], v = r2[i];
    int ret = 0;
    for (int j = 1; j <= res; j++)
      if (!co[0][u][j] and !co[1][v][j]) ret = j;
    if (ret) {
      co[0][u][ret] = v;
      co[1][v][ret] = u;
      continue;
    }
    int c1 = 0, c2 = 0;
    for (int j = 1; j <= res; j++) {
      if (!co[0][u][j]) c1 = j;
      if (!co[1][v][j]) c2 = j;
    }
    dfs(0, u, v, c1, c2);
  }
  for (int k = 1; k <= n; k++)
    for (int j = 1; j <= res; j++)
      if (co[0][k][j]) res1[k][co[0][k][j]] = j;
  cout << res << "\n";
  for (int j = 1; j <= num; j++) cout << res1[r1[j]][r2[j]] << " ";
}