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;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const int maxn = 2e3 + 10;
const int maxm = 1e5 + 10;
const int base = 29;
const int mod = 1e9 + 7;
const int INF = 1e9 + 100;
const int SQ = 317;
int Cmp;
int mark[maxn];
int v[maxm], u[maxm], deg[maxn], has[maxn][maxn], e[maxm];
int vc[5];
inline void dfs(int node, int id) {
  int edgeid = has[node][vc[id]] - 1;
  if (edgeid < 0) return;
  int nxt = v[edgeid] == node ? u[edgeid] : v[edgeid];
  has[node][vc[id]] = 0;
  has[nxt][vc[id]] = 0;
  dfs(nxt, id ^ 1);
  has[node][vc[id ^ 1]] = edgeid + 1;
  has[nxt][vc[id ^ 1]] = edgeid + 1;
  e[edgeid] = vc[id ^ 1];
}
int res;
int32_t main() {
  int a = in(), b = in(), m = in();
  for (int i = 0; i < m; i++) {
    v[i] = in(), u[i] = in() + a;
    deg[v[i]]++;
    deg[u[i]]++;
    res = max(res, max(deg[v[i]], deg[u[i]]));
  }
  for (int i = 0; i < m; i++) {
    bool fl = false;
    for (int col = 1; col <= res; col++) {
      if (has[v[i]][col] == 0 && has[u[i]][col] == 0 && col <= res) {
        has[v[i]][col] = has[u[i]][col] = i + 1;
        e[i] = col;
        fl = true;
        break;
      }
    }
    if (!fl) {
      Cmp++;
      for (int col = 1; col <= res; col++) {
        if (has[v[i]][col] && !has[u[i]][col]) vc[0] = col;
        if (has[v[i]][col] == 0 && has[u[i]][col]) vc[1] = col;
      }
      dfs(v[i], 0);
      has[v[i]][vc[0]] = has[u[i]][vc[0]] = i + 1;
      e[i] = vc[0];
    }
  }
  cout << res << "\n";
  for (int i = 0; i < m; i++) cout << e[i] << " ";
}