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 a, b, m, num[((int)3030)], ans, c[((int)101 * 1000)];
pair<int, int> e[((int)3030)][((int)3030)];
vector<pair<int, int> > ed;
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> a >> b >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v = v * 2;
    u = u * 2 + 1;
    num[v]++;
    num[u]++;
    ed.push_back({v, u});
  }
  for (int i = 0; i < ((int)3030); i++) ans = max(ans, num[i]);
  cout << ans << "\n";
  for (int i = 0; i < m; i++) {
    int v = ed[i].first, u = ed[i].second;
    int col = -1;
    for (int j = 0; j < ans; j++)
      if (!e[v][j].first && !e[u][j].first) {
        col = j;
        break;
      }
    if (col != -1) {
      c[i] = col;
      e[v][col] = {u, i};
      e[u][col] = {v, i};
      continue;
    }
    int c1, c2;
    for (int j = 0; j < ans; j++) {
      if (!e[v][j].first) c1 = j;
      if (!e[u][j].first) c2 = j;
    }
    int x = u;
    int now = c1, rev = c2;
    c[i] = c1;
    e[v][c1] = {u, i};
    e[u][c2] = {v, i};
    while (1) {
      int new_x = e[x][now].first, id = e[x][now].second;
      e[x][now] = e[x][rev];
      if (new_x == 0) {
        e[x][rev].first = 0;
        break;
      }
      c[id] = rev;
      e[x][rev] = {new_x, id};
      swap(now, rev);
      x = new_x;
    }
  }
  for (int i = 0; i < m; i++) cout << c[i] + 1 << " ";
  return 0;
}