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;
using uint = unsigned int;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
template <class T, class U>
void chmax(T& x, U y) {
  if (x < y) x = y;
}
template <class T, class U>
void chmin(T& x, U y) {
  if (y < x) x = y;
}
template <class T>
void mkuni(V<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
V<int> bipartite_edge_coloring(int N, V<pair<int, int>> es) {
  using P = pair<int, int>;
  int M = es.size();
  int D = 0;
  {
    V<int> d(N);
    for (P e : es) d[e.first]++, d[e.second]++;
    for (int i = 0; i < int(N); i++) chmax(D, d[i]);
  }
  VV<int> vc2e(N, V<int>(D, -1));
  V<int> col(M, -1);
  auto color = [&](int e, int c) {
    int x = es[e].first, y = es[e].second;
    if (col[e] != -1) {
      vc2e[x][col[e]] = -1;
      vc2e[y][col[e]] = -1;
    }
    col[e] = c;
    vc2e[x][c] = e, vc2e[y][c] = e;
  };
  V<int> buf(M);
  for (int t = 0; t < int(M); t++) {
    int x = es[t].first, y = es[t].second;
    int c0 = 0, c1 = 0;
    while (vc2e[x][c0] != -1) c0++;
    while (vc2e[y][c1] != -1) c1++;
    void(0);
    void(0);
    void(0);
    void(0);
    if (c0 == c1) {
      color(t, c0);
      continue;
    }
    int v = x, c = c1, I = 0;
    while (vc2e[v][c] != -1) {
      int e = vc2e[v][c];
      void(0);
      v ^= es[e].first ^ es[e].second;
      c ^= c0 ^ c1;
      buf[I++] = e;
    }
    v = x;
    for (int i = 0; i < int(I); i++) {
      int e = buf[i];
      col[e] ^= c0 ^ c1;
      swap(vc2e[v][c0], vc2e[v][c1]);
      v ^= es[e].first ^ es[e].second;
    }
    swap(vc2e[v][c0], vc2e[v][c1]);
    color(t, c1);
  }
  return col;
}
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  using P = pair<int, int>;
  V<P> es;
  for (int i = 0; i < int(M); i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    es.emplace_back(x, y + A);
  }
  auto c = bipartite_edge_coloring(A + B, es);
  int D = 0;
  for (int v : c) chmax(D, v + 1);
  cout << D << endl;
  for (int v : c) cout << v + 1 << " ";
  cout << endl;
}