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;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
using graph = vector<vi>;
using matrix = graph;
const int MAXN = 2e3 + 4;
const int INF = 0x3f3f3f3f;
const ll INFL = 1e18 + 4;
const ll mod = 1e9 + 7;
int cor[MAXN][MAXN], dg[MAXN], core[MAXN][MAXN];
vii edges;
graph g;
int main() {
  int n1, n2, m, n;
  scanf("%d %d %d", &n1, &n2, &m);
  n = n1 + n2;
  g.assign(n + 1, vi());
  int u, v, mx = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &u, &v);
    v += n1;
    edges.emplace_back(u, v);
    g[u].emplace_back(v);
    g[v].emplace_back(u);
    dg[u]++;
    dg[v]++;
    mx = max(mx, max(dg[u], dg[v]));
  }
  bool yes;
  for (int x, i = 1; i <= n1; ++i) {
    for (auto y : g[i]) {
      x = i;
      yes = 0;
      for (int c = 1; c <= mx; ++c) {
        if (!cor[x][c] && !cor[y][c]) {
          cor[x][c] = y;
          cor[y][c] = x;
          core[x][y] = c;
          core[y][x] = c;
          yes = 1;
          break;
        }
      }
      if (!yes) {
        int c1 = 1, c2 = 1;
        while (cor[x][c1]) c1++;
        while (cor[y][c2]) c2++;
        while (y) {
          int nxt = cor[y][c1];
          core[x][y] = c1;
          core[y][x] = c1;
          cor[x][c1] = y;
          cor[y][c1] = x;
          swap(c1, c2);
          x = y;
          y = nxt;
        }
        cor[x][c1] = 0;
      }
    }
  }
  printf("%d\n", mx);
  for (auto e : edges) {
    printf("%d ", core[e.first][e.second]);
  }
}