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 = 2e3 + 5, M = 1e5 + 5;
int n, n1, k, cc, res, C[N], Dt[N], Assigned[N], color[M], visited[N];
vector<pair<int, int>> S[N];
void Enter() {
  cin >> n1 >> n >> k;
  n += n1;
  int u, v;
  for (int i = 1; i <= k; i++) {
    cin >> u >> v;
    v += n1;
    S[u].emplace_back(v, i);
    S[v].emplace_back(u, i);
    C[u]++;
    C[v]++;
  }
}
bool FindPath(int u) {
  if (visited[u] != cc)
    visited[u] = cc;
  else
    return false;
  if (C[u] != res) {
    Dt[u] = 0;
    Assigned[u] = 0;
    return true;
  }
  for (pair<int, int> e : S[u])
    if (!color[e.second] || color[e.second] == res) {
      int v = e.first;
      if (!Assigned[v]) {
        Assigned[v] = u;
        Assigned[u] = v;
        color[Dt[v]] = 0;
        Dt[u] = Dt[v] = e.second;
        color[Dt[v]] = res;
        return true;
      }
    }
  for (pair<int, int> e : S[u])
    if (!color[e.second] || color[e.second] == res) {
      int v = e.first;
      if (FindPath(Assigned[v])) {
        Assigned[v] = u;
        Assigned[u] = v;
        color[Dt[v]] = 0;
        Dt[u] = Dt[v] = e.second;
        color[Dt[v]] = res;
        return true;
      }
    }
  return false;
}
void Process() {
  for (int i = 1; i <= n; i++) res = max(res, C[i]);
  cout << res << '\n';
  for (; res; res--) {
    fill(Dt + 1, Dt + n + 1, 0);
    fill(Assigned + 1, Assigned + n + 1, 0);
    for (int j = 1; j <= n; j++)
      if (!Assigned[j] && C[j] == res) {
        ++cc;
        FindPath(j);
      }
    for (int j = 1; j <= n; j++)
      if (!Assigned[j]) {
        ++cc;
        FindPath(j);
      }
    for (int j = 1; j <= n; j++)
      if (Assigned[j]) C[j]--;
  }
  for (int i = 1; i <= k; i++) cout << color[i] << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Enter();
  Process();
}