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;
constexpr int N = 2e3 + 10;
constexpr int M = 1e5 + 10;
constexpr int MOD = 1e9 + 7;
int n, m, u[M], v[M], e, ans, cl[M], c1, c2, cnt[N], who[N][N];
vector<int> node[N];
void dfs(int ve) {
  int cc1 = who[ve][c1];
  int cc2 = who[ve][c2];
  if (ve > 1000) {
    if (cc2) dfs(u[cc2]);
  } else {
    if (cc1) dfs(v[cc1] + 1000);
  }
  swap(who[ve][c1], who[ve][c2]);
  if (cc1) cl[cc1] = c2;
  if (cc2) cl[cc2] = c1;
}
void add(int id) {
  memset(cnt, 0, sizeof(cnt));
  for (auto i : node[u[id]]) cnt[cl[i]] = 1;
  for (auto i : node[v[id] + 1000]) cnt[cl[i]] += 2;
  for (int i = 1; i <= ans; i++) {
    if (!cnt[i]) {
      cl[id] = i;
      node[u[id]].push_back(id);
      node[v[id] + 1000].push_back(id);
      who[u[id]][i] = id;
      who[v[id] + 1000][i] = id;
      return;
    }
  }
  for (auto i : node[u[id]]) {
    if (cnt[cl[i]] == 1) {
      c1 = cl[i];
      break;
    }
  }
  for (auto i : node[v[id] + 1000]) {
    if (cnt[cl[i]] == 2) {
      c2 = cl[i];
      break;
    }
  }
  cl[id] = c1;
  node[u[id]].push_back(id);
  node[v[id] + 1000].push_back(id);
  dfs(u[id]);
  who[u[id]][c1] = id;
  who[v[id] + 1000][c1] = id;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> e;
  for (int i = 0; i < e; i++) {
    cin >> u[i] >> v[i];
    node[u[i]].push_back(v[i] + 1000);
    node[v[i] + 1000].push_back(u[i]);
  }
  for (int i = 1; i <= n; i++) ans = max(ans, (int)node[i].size());
  for (int i = 1; i <= m; i++) ans = max(ans, (int)node[i + 1000].size());
  for (int i = 0; i < N; i++) node[i].clear();
  for (int i = 0; i < e; i++) add(i);
  cout << ans << '\n';
  for (int i = 0; i < e; i++) cout << cl[i] << ' ';
  cout << '\n';
  return 0;
}