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;
const int N = 1e5 + 10;
const long long INF = 1LL << 60;
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &second) { return '"' + second + '"'; }
string to_string(const char *second) { return to_string((string)second); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
long long maxd;
vector<vector<long long>> taken, col;
long long deg[N];
void solve() {
  long long a, b, m;
  cin >> a >> b >> m;
  long long n = a + b;
  vector<pair<long long, long long>> vp;
  for (long long i = 0; i < m; ++i) {
    long long u, v;
    cin >> u >> v;
    vp.emplace_back(make_pair(u, a + v));
    deg[u]++;
    deg[a + v]++;
    chmax(maxd, deg[u]);
    chmax(maxd, deg[a + v]);
  }
  taken.assign(n + 1, vector<long long>(maxd + 1, 0));
  col.assign(n + 1, vector<long long>(n + 1, 0));
  for (long long i = 0; i < m; ++i) {
    long long u = vp[i].first;
    long long v = vp[i].second;
    long long cu = -1, cv = -1;
    bool ok = true;
    for (long long j = 1; j <= maxd; ++j) {
      if (!taken[u][j] && !taken[v][j]) {
        taken[u][j] = v;
        taken[v][j] = u;
        col[u][v] = col[v][u] = j;
        ok = false;
        break;
      }
      if (taken[u][j] && !taken[v][j]) {
        cu = j;
      }
      if (!taken[u][j] && taken[v][j]) {
        cv = j;
      }
    }
    if (ok) {
      while (taken[v][cv]) {
        long long t = taken[v][cv];
        taken[v][cv] = u;
        taken[u][cv] = v;
        col[u][v] = col[v][u] = cv;
        swap(cv, cu);
        u = v;
        v = t;
      }
      taken[v][cv] = u;
      taken[u][cv] = v;
      col[u][v] = col[v][u] = cv;
      taken[v][cu] = 0;
    }
  }
  cout << maxd << endl;
  for (auto edg : vp) {
    cout << col[edg.first][edg.second] << " ";
  }
  cout << endl;
}
int main() {
  long long Tests = 1;
  while (Tests--) {
    solve();
  }
  return 0;
}