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 <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 62;
const int mods = 1e9 + 7;
const int MAXN = 2005;
const int INF = 0x3f3f3f3f;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
pair<int, int> e[100050];
int f[MAXN][MAXN], flag[MAXN][MAXN], d[MAXN], cnt = 0;
void dfs(int u, int v, int x, int y) {
  int t = flag[v][x];
  f[u][v] = f[v][u] = x;
  flag[u][x] = v, flag[v][x] = u;
  if (t)
    dfs(v, t, y, x);
  else
    flag[v][y] = 0;
}
signed main() {
  int a = read(), b = read(), m = read(), ans = 0;
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read() + a;
    upmax(ans, ++d[u]), upmax(ans, ++d[v]);
    e[i] = make_pair(u, v);
    int x = 1, y = 1;
    while (flag[u][x]) x++;
    while (flag[v][y]) y++;
    if (x > y) swap(x, y), swap(u, v);
    if (x == y)
      f[u][v] = f[v][u] = x, flag[u][x] = v, flag[v][x] = u;
    else
      dfs(u, v, x, y);
  }
  printf("%d\n", ans);
  for (int i = 1; i <= m; i++) printf("%d ", f[e[i].first][e[i].second]);
  return 0;
}