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;
const int inf = 1e9;
const long long Inf = 1e10;
const int N = 100005;
const int P = 1000000007;
int IN() {
  int x = 0;
  int f = 0, ch = 0;
  for ((ch = getchar()); ch < 48 || ch > 57; (ch = getchar())) f = (ch == '-');
  for (; ch >= 48 && ch <= 57; (ch = getchar()))
    x = (x << 1) + (x << 3) + ch - 48;
  return f ? (-x) : x;
}
int Pow(int x, int y, int p) {
  int A = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) A = (long long)A * x % p;
  return A;
}
int u[2005][1005], n, m, c, ans;
int col[2005][2005], D[N];
vector<pair<int, int> > ord, que;
void solve(pair<int, int> e) {
  int a = e.first, b = e.second;
  for (int c = (int)1; c <= (int)ans; c++) {
    if (!u[a][c] && !u[b][c]) {
      u[a][c] = b;
      u[b][c] = a;
      col[a][b] = col[b][a] = c;
      return;
    }
  }
  for (int c = (int)1; c <= (int)ans; c++) {
    if (!u[a][c]) {
      int d = u[b][c];
      if (d) {
        u[d][c] = 0;
        u[b][c] = 0;
        que.push_back(make_pair(b, d));
      }
      solve(e);
      return;
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &c);
  for (int i = (int)1; i <= (int)c; i++) {
    int X = IN(), Y = IN();
    ord.push_back(make_pair(X, Y + n));
    que.push_back(make_pair(X, Y + n));
    D[X]++, D[Y + n]++;
  }
  for (int i = (int)1; i <= (int)n + m; i++) ans = max(ans, D[i]);
  while (que.size()) {
    auto i = que.back();
    que.pop_back();
    solve(i);
  }
  printf("%d\n", ans);
  for (auto i : ord) printf("%d ", col[i.first][i.second]);
  return 0;
}