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 T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long nextLong() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int MAX_N = 1005;
int AtoB[MAX_N][MAX_N];
int BtoA[MAX_N][MAX_N];
int color[MAX_N][MAX_N];
int degA[MAX_N];
int degB[MAX_N];
void dfsB(int b, int s, int t);
void dfsA(int a, int s, int t) {
  int b = AtoB[a][s];
  if (b != -1) dfsB(b, t, s);
  swap(AtoB[a][t], AtoB[a][s]);
}
void dfsB(int b, int s, int t) {
  int a = BtoA[b][s];
  if (a != -1) dfsA(a, t, s);
  swap(BtoA[b][t], BtoA[b][s]);
}
void add_edge(int a, int b, int D) {
  for (int d = 0; d < D; d++) {
    if (AtoB[a][d] == -1 && BtoA[b][d] == -1) {
      AtoB[a][d] = b;
      BtoA[b][d] = a;
      return;
    }
  }
  int s = -1, t = -1;
  for (int d = 0; d < D; d++) {
    if (BtoA[b][d] == -1) s = d;
    if (AtoB[a][d] == -1) t = d;
  }
  dfsA(a, s, t);
  AtoB[a][s] = b;
  BtoA[b][s] = a;
  return;
}
int main2() {
  memset(AtoB, (-1), sizeof(AtoB));
  memset(BtoA, (-1), sizeof(BtoA));
  memset(color, (-1), sizeof(color));
  memset(degA, (0), sizeof(degA));
  memset(degB, (0), sizeof(degB));
  int A = nextInt();
  int B = nextInt();
  int M = nextInt();
  vector<pair<int, int>> es;
  for (int m = 0, _n = (int)(M); m < _n; ++m) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    es.emplace_back(a, b);
    degA[a]++;
    degB[b]++;
  }
  int D = 0;
  for (int a = 0, _n = (int)(A); a < _n; ++a) chmax(D, degA[a]);
  for (int b = 0, _n = (int)(B); b < _n; ++b) chmax(D, degB[b]);
  for (auto e : es) {
    add_edge(e.first, e.second, D);
  }
  for (int a = 0, _n = (int)(A); a < _n; ++a) {
    for (int d = 0, _n = (int)(D); d < _n; ++d) {
      int b = AtoB[a][d];
      if (b != -1) {
        color[a][b] = d;
      }
    }
  }
  printf("%d\n", D);
  for (int i = 0, _n = (int)(es.size()); i < _n; ++i) {
    if (i > 0) printf(" ");
    printf("%d", (1 + color[es[i].first][es[i].second]));
  }
  printf("\n");
  return 0;
}
int main() {
  main2();
  return 0;
}