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>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const long double EPS = 1e-9;
vector<vector<pair<int, int>>> g;
vector<pair<int, int>> es;
vector<int> cs;
int max_deg;
void dfs(int v, const vector<int> &cc, int it, int le) {
  for (auto vv : g[v]) {
    if (vv.second == le) continue;
    if (cs[vv.second] == cc[it]) {
      dfs(vv.first, cc, it ^ 1, vv.second);
      cs[vv.second] = cc[it ^ 1];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(14);
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  int n = n1 + n2;
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    b += n1;
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
    es.push_back(make_pair(a, b));
    max_deg = max(max_deg, (int)g[a].size());
    max_deg = max(max_deg, (int)g[b].size());
  }
  cs.assign(m, -1);
  for (int ie = 0; ie < es.size(); ++ie) {
    int a = es[ie].first;
    int b = es[ie].second;
    vector<bool> csa(max_deg, false), csb(max_deg, false);
    for (auto to : g[a]) {
      int col = cs[to.second];
      if (col != -1) csa[col] = true;
    }
    for (auto to : g[b]) {
      int col = cs[to.second];
      if (col != -1) csb[col] = true;
    }
    int col = -1;
    for (int i = 0; i < max_deg; ++i) {
      if (!csa[i] && !csb[i]) {
        col = i;
        break;
      }
    }
    if (col != -1) {
      cs[ie] = col;
      continue;
    }
    int c1 = -1, c2 = -1;
    for (int i = 0; i < max_deg; ++i) {
      if (csa[i] && !csb[i]) {
        c1 = i;
      } else if (csb[i] && !csa[i]) {
        c2 = i;
      }
    }
    vector<int> cc = {c1, c2};
    dfs(b, cc, 1, -1);
    cs[ie] = c2;
  }
  cout << max_deg << endl;
  for (int i = 0; i < cs.size(); ++i) {
    cout << cs[i] + 1 << ' ';
  }
  return 0;
};