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 = 2002;
int a, b;
vector<pair<int, int> > g[N];
vector<pair<int, int> > edges;
int C[N][N];
int D;
bool seen[N];
bool dfs(int x, int y, int cx, int cy) {
  if (seen[x]) return false;
  seen[x] = true;
  if (C[y][cy] == -1) {
    assert(C[x][cx] == y && C[y][cx] == x);
    C[x][cx] = -1;
    C[y][cx] = -1;
    C[x][cy] = y;
    C[y][cy] = x;
    return true;
  } else if (dfs(y, C[y][cy], cy, cx)) {
    C[y][cy] = x;
    C[x][cy] = y;
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  int a, b, m;
  cin >> a >> b >> m;
  for (int _n(m), i(0); i < _n; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    y += a;
    g[x].emplace_back(y, i);
    g[y].emplace_back(x, i);
    edges.emplace_back(x, y);
  }
  D = 0;
  for (int _n(a + b), i(0); i < _n; i++) D = max(D, (int)g[i].size());
  memset((C), (-1), sizeof(C));
  for (int k = 0; k < (int)edges.size(); ++k) {
    int x = edges[k].first;
    int y = edges[k].second;
    bool done = false;
    for (int i = 0; i < D; ++i) {
      if (C[x][i] == -1 && C[y][i] == -1) {
        C[x][i] = y;
        C[y][i] = x;
        done = true;
        break;
      }
    }
    if (!done) {
      int cx = -1, cy = -1;
      for (int i = 0; i < D; ++i) {
        if (C[y][i] == -1 && C[x][i] != -1 && cx == -1) {
          cx = i;
        }
        if (C[y][i] != -1 && C[x][i] == -1 && cy == -1) {
          cy = i;
        }
      }
      memset((seen), (0), sizeof(seen));
      dfs(x, y, cx, cy);
    }
  }
  cout << D << endl;
  for (auto el : edges) {
    int x = el.first;
    int y = el.second;
    int c = -1;
    for (int _n(D), i(0); i < _n; i++)
      if (C[x][i] == y && C[y][i] == x) {
        c = i;
        break;
      }
    assert(c != -1);
    cout << c + 1 << " ";
  }
  cout << endl;
  return 0;
}