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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e3 + 100, OO = 1e5 + 100, M = 1e9 + 7, P = 6151, SQ = 1300;
vector<int> v[N];
int x[OO], y[OO], wh[N][N], st[N], dlt, c[4], mark[OO];
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m, k;
  cin >> n >> m;
  k = n;
  n += m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    y[i] += k;
    v[x[i]].push_back(i);
    v[y[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) dlt = max(dlt, (int)v[i].size());
  for (int i = 1; i <= m; i++) {
    bool is = false;
    for (int j = 1; j <= dlt; j++) {
      if (wh[x[i]][j] == 0 && wh[y[i]][j] == 0) {
        is = true;
        mark[i] = j;
        break;
      }
      if (wh[x[i]][j] == 0) c[0] = j;
      if (wh[y[i]][j] == 0) c[1] = j;
    }
    if (!is) {
      int t = y[i], pre = i;
      bool b = false;
      mark[i] = c[0], wh[x[i]][c[0]] = i;
      while (true) {
        int nxt = wh[t][c[b]];
        wh[t][c[b]] = pre;
        if (nxt != 0) {
          wh[t][c[b ^ 1]] = nxt;
          mark[nxt] = c[b ^ 1];
          pre = nxt;
          t = x[nxt] + y[nxt] - t;
          b ^= 1;
        } else {
          wh[t][c[b ^ 1]] = 0;
          break;
        }
      }
    } else
      wh[x[i]][mark[i]] = wh[y[i]][mark[i]] = i;
  }
  cout << dlt << endl;
  for (int i = 1; i <= m; i++) cout << mark[i] << " ";
  return 0;
}