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;
template <class T, class U>
inline void Max(T &a, U b) {
  if (a < b) a = b;
}
template <class T, class U>
inline void Min(T &a, U b) {
  if (a > b) a = b;
}
inline void add(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
vector<int> g[1005];
int d[1005], f[1005], cnt[1005], U[100005], V[100005], co[100005];
pair<int, int> c[2005][1005];
void dfs(int u, int first, int v, int second, int k) {
  int i = c[v][second].first, from = c[v][second].second;
  if (c[from][first].first == 0) {
    c[from][first] = make_pair(i, v), c[v][first] = make_pair(i, from);
    co[i] = first;
    c[from][second] = make_pair(0, 0), c[v][second] = make_pair(0, 0);
    c[u][second] = make_pair(k, v), c[v][second] = make_pair(k, u),
    co[k] = second;
    return;
  }
  dfs(v, second, from, first, i);
  c[u][second] = make_pair(k, v), c[v][second] = make_pair(k, u),
  co[k] = second;
}
int main() {
  int T, i, j, k, m, n;
  int a, b;
  scanf("%d%d%d", &a, &b, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &j, &k);
    j--, k--;
    d[j]++, f[k]++;
    U[i] = j, V[i] = k + a;
  }
  int ans = 0;
  for (i = 0; i < a; i++) Max(ans, d[i]);
  for (i = 0; i < b; i++) Max(ans, f[i]);
  printf("%d\n", ans);
  for (i = 1; i <= m; i++) {
    int u = U[i], v = V[i], ok = 0;
    for (j = 1; j <= ans; j++) {
      cnt[j] = 0;
      if (c[u][j].first == 0 && c[v][j].first == 0) {
        co[i] = j;
        ok = 1;
        c[u][j] = make_pair(i, v), c[v][j] = make_pair(i, u);
        break;
      }
    }
    if (ok) continue;
    for (j = 1; j <= ans; j++) {
      if (c[u][j].first) cnt[j] |= 1;
      if (c[v][j].first) cnt[j] |= 2;
    }
    for (j = 1; j <= ans; j++)
      if (cnt[j] != 3 && cnt[j]) break;
    int first = j, second = -1;
    for (j++; j <= ans; j++)
      if (cnt[j] == 3 - cnt[first]) {
        second = j;
        break;
      }
    assert(second > 0);
    if (cnt[first] == 1)
      dfs(u, first, v, second, i);
    else
      dfs(u, second, v, first, i);
  }
  for (i = 1; i <= m; i++) printf("%d ", co[i]);
  puts("");
  return 0;
}