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;
int n1, n2, m, used[2001][1001], ans[100001], sum[100001];
vector<pair<int, int>> graph[2001];
void solve(int x, int y, int c1, int c2, int id) {
  int tmp = used[y][c1];
  used[x][c1] = used[y][c1] = id;
  if (tmp == 0) {
    used[y][c2] = 0;
    return;
  }
  solve(y, sum[tmp] - y, c2, c1, tmp);
}
int main() {
  cin >> n1 >> n2 >> m;
  for (int i = 1; i <= m; i += 1) {
    int a, b;
    cin >> a >> b;
    b += n1;
    sum[i] = a + b;
    graph[a].push_back({b, i});
    graph[b].push_back({a, i});
  }
  int maxi = 0;
  for (int i = 1; i <= n1 + n2; i += 1) {
    maxi = max(maxi, (int)graph[i].size());
  }
  cout << maxi << endl;
  for (int i = 1; i <= n1; i += 1) {
    for (pair<int, int> j : graph[i]) {
      int p1 = 1, p2 = 1;
      while (used[i][p1]) {
        p1 += 1;
      }
      while (used[j.first][p2]) {
        p2 += 1;
      }
      if (p1 == p2) {
        used[i][p1] = used[j.first][p2] = j.second;
        continue;
      }
      solve(i, j.first, p1, p2, j.second);
    }
  }
  for (int i = 1; i <= n1; i += 1) {
    for (int j = 1; j <= maxi; j += 1) {
      ans[used[i][j]] = j;
    }
  }
  for (int i = 1; i <= m; i += 1) {
    cout << ans[i] << " ";
  }
  cout << endl;
}