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 aridad[2001];
int g[2001][1001];
int maxaridad = 0;
int lista[2001];
int sol[1000000];
int idarista[2001][2001];
int main() {
  ios::sync_with_stdio(false);
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  for (int caso = 1; caso <= m; caso++) {
    int u, v;
    cin >> u >> v;
    v += 1000;
    idarista[u][v] = caso;
    aridad[u]++;
    aridad[v]++;
    maxaridad = max(maxaridad, max(aridad[u], aridad[v]));
    bool trobat = false;
    int cu, cv;
    for (int c = 1; c <= maxaridad and not trobat; c++) {
      if (g[u][c] == 0 and g[v][c] == 0) {
        trobat = true;
        g[u][c] = v;
        g[v][c] = u;
      } else if (g[u][c] == 0)
        cv = c;
      else if (g[v][c] == 0)
        cu = c;
    }
    if (not trobat) {
      int ilista = 0;
      lista[ilista++] = v;
      lista[ilista++] = g[v][cv];
      for (;; ilista++) {
        if (ilista % 2 == 0 and g[lista[ilista - 1]][cu])
          lista[ilista] = g[lista[ilista - 1]][cu];
        else if (ilista % 2 == 1 and g[lista[ilista - 1]][cv])
          lista[ilista] = g[lista[ilista - 1]][cv];
        else
          break;
      }
      ilista--;
      if (ilista % 2 == 0)
        g[lista[ilista]][cu] = 0;
      else
        g[lista[ilista]][cv] = 0;
      ilista--;
      for (; ilista >= 0; ilista--) {
        int w1 = lista[ilista];
        int w2 = lista[ilista + 1];
        if (ilista % 2 == 0) {
          g[w1][cu] = w2;
          g[w2][cu] = w1;
        } else {
          g[w1][cv] = w2;
          g[w2][cv] = w1;
        }
      }
      g[u][cv] = v;
      g[v][cv] = u;
    }
  }
  for (int u = 1; u <= n1; u++)
    for (int c = 1; c <= maxaridad; c++)
      if (g[u][c]) sol[idarista[u][g[u][c]]] = c;
  cout << maxaridad << endl;
  for (int i = 1; i <= m; i++) {
    if (i > 1) cout << " ";
    cout << sol[i];
  }
  cout << endl;
}