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;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = 2 * acos((long double)0);
const int maxn = 2010;
int a, b, m;
vector<pair<int, int> > edges;
int d[maxn];
int g[maxn][maxn];
int ans[maxn][maxn];
int vis[maxn][maxn];
void join(int u, int v, int c) {
  int old = ans[u][v];
  if (old) {
    if (g[u][old] == v) g[u][old] = 0;
    if (g[v][old] == u) g[v][old] = 0;
  }
  g[u][c] = v;
  g[v][c] = u;
  ans[u][v] = ans[v][u] = c;
}
void solve() {
  scanf("%d%d%d", &a, &b, &m);
  int D = 0;
  for (int i = (0); i < (m); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    v += a;
    edges.push_back(make_pair(u, v));
    D = max(D, ++d[u]);
    D = max(D, ++d[v]);
  }
  for (int i = (0); i < (m); i++) {
    int u = edges[i].first;
    int v = edges[i].second;
    int flag = 0;
    for (int j = (1); j < (D + 1); j++)
      if (!g[u][j] && !g[v][j]) {
        join(u, v, j);
        flag = 1;
        break;
      }
    if (!flag) {
      int c[2];
      for (int j = (1); j < (D + 1); j++) {
        if (g[u][j] && !g[v][j]) c[0] = j;
        if (!g[u][j] && g[v][j]) c[1] = j;
      }
      int cur = v, cnt = 1;
      vector<int> t;
      while (1) {
        t.push_back(cur);
        int nxt = g[cur][c[cnt]];
        if (!nxt || vis[cur][nxt]) break;
        vis[cur][nxt] = 1;
        cur = nxt;
        cnt ^= 1;
      }
      cnt = 0;
      for (int j = (0); j < (int((t).size()) - 1); j++) {
        join(t[j], t[j + 1], c[cnt]);
        vis[t[j]][t[j + 1]] = 0;
        cnt ^= 1;
      }
      join(u, v, c[1]);
    }
  }
  printf("%d\n", D);
  for (int i = (0); i < (m); i++) {
    int u = edges[i].first;
    int v = edges[i].second;
    printf("%d ", ans[u][v]);
  }
}
int main() {
  solve();
  return 0;
}