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>
inline void read(T& num) {
  num = 0;
  bool f = true;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = false;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    num = num * 10 + ch - '0';
    ch = getchar();
  }
  num = f ? num : -num;
}
int out[100];
template <class T>
inline void write(T x, char ch) {
  if (x == 0) {
    putchar('0');
    putchar(ch);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int num = 0;
  while (x) {
    out[num++] = (x % 10);
    x = x / 10;
  }
  for (int i = (num - 1); i >= (0); i--) putchar(out[i] + '0');
  putchar(ch);
}
const int N = 1024;
int id[N][N], cx[N][N], cy[N][N], dx[N], dy[N], ans[N], nx, ny;
void dfs(int x[][N], int y[][N], int u, int v, int cu, int cv) {
  int w = y[v][cv];
  if (!x[w][cu]) {
    x[w][cu] = v, y[v][cu] = w;
    x[w][cv] = 0;
  } else
    dfs(y, x, v, w, cv, cu);
  x[u][cv] = v;
  y[v][cv] = u;
}
int main() {
  int m;
  read(nx);
  read(ny);
  read(m);
  int u, v;
  for (int i = 1; i <= m; ++i) {
    read(u);
    read(v);
    id[u][v] = i;
    ++dx[u];
    ++dy[v];
  }
  int d =
      max(*max_element(dx + 1, dx + 1 + nx), *max_element(dy + 1, dy + 1 + ny));
  write(d, '\n');
  for (int u = (1); u <= (nx); u++)
    for (int v = (1); v <= (ny); v++)
      if (id[u][v]) {
        int c = 1;
        while (cx[u][c] || cy[v][c]) ++c;
        if (c <= d) {
          cx[u][c] = v;
          cy[v][c] = u;
          continue;
        }
        int cu = 1, cv = 1;
        while (cy[v][cu]) ++cu;
        while (cx[u][cv]) ++cv;
        dfs(cx, cy, u, v, cu, cv);
      }
  for (int u = (1); u <= (nx); u++)
    for (int c = (1); c <= (d); c++)
      if (cx[u][c]) ans[id[u][cx[u][c]]] = c;
  for (int i = (1); i <= (m); i++) write(ans[i], ' ');
  puts("");
  return 0;
}