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, k, ta, tb, i, ans[100005], tc;
vector<int> va[2][1005], vb[2][1005], vc[2][1005], vd[2][1005], ve, vf;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int a = 0; a < k; a++) {
    scanf("%d%d", &ta, &tb);
    ta--;
    tb--;
    va[0][ta].push_back(tb);
    va[1][tb].push_back(ta);
    vb[0][ta].push_back(a);
    vb[1][tb].push_back(a);
    vd[0][ta].push_back(va[1][tb].size() - 1);
    vd[1][tb].push_back(va[0][ta].size() - 1);
    ans[a] = -1;
  }
  for (int a = 0; a < n; a++) i = max(i, (int)va[0][a].size());
  for (int a = 0; a < m; a++) i = max(i, (int)va[1][a].size());
  for (int a = 0; a < n; a++)
    for (int b = 0; b < i; b++) vc[0][a].push_back(-1);
  for (int a = 0; a < m; a++)
    for (int b = 0; b < i; b++) vc[1][a].push_back(-1);
  for (int a = 0; a < n; a++)
    for (int b = 0; b < va[0][a].size(); b++) {
      tc = -1;
      ta = -1;
      tb = -1;
      for (int c = 0; c < i; c++) {
        if (vc[0][a][c] == -1 && vc[1][va[0][a][b]][c] == -1) {
          tc = c;
          break;
        } else if (vc[1][va[0][a][b]][c] == -1)
          ta = c;
        else if (vc[0][a][c] == -1)
          tb = c;
      }
      if (tc != -1)
        tb = tc;
      else if (ta == -1 || tb == -1)
        while (1) {
        }
      ve.clear();
      vf.clear();
      ve.push_back(a);
      vf.push_back(b);
      while (1) {
        tc = vc[ve.size() % 2][va[1 - ve.size() % 2][ve.back()][vf.back()]]
               [(ve.size() & 1) ? tb : ta];
        if (tc == -1) break;
        ve.push_back(va[1 - ve.size() % 2][ve.back()][vf.back()]);
        vf.push_back(tc);
      }
      for (int c = 0; c < ve.size(); c++)
        if (ans[vb[c % 2][ve[c]][vf[c]]] != -1) {
          vc[c % 2][ve[c]][ans[vb[c % 2][ve[c]][vf[c]]]] = -1;
          vc[1 - c % 2][va[c % 2][ve[c]][vf[c]]][ans[vb[c % 2][ve[c]][vf[c]]]] =
              -1;
        }
      for (int c = 0; c < ve.size(); c++) {
        ans[vb[c % 2][ve[c]][vf[c]]] = (c & 1) ? ta : tb;
        vc[c % 2][ve[c]][(c & 1) ? ta : tb] = vf[c];
        vc[1 - c % 2][va[c % 2][ve[c]][vf[c]]][(c & 1) ? ta : tb] =
            vd[c % 2][ve[c]][vf[c]];
      }
    }
  printf("%d\n", i);
  for (int a = 0; a < k; a++)
    printf("%d%c", ans[a] + 1, a == k - 1 ? '\n' : ' ');
  return 0;
}