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 k;
vector<vector<int>> graph;
vector<pair<int, int>> edges;
bool vertice_colors[2010][1010];
vector<int> edge_color;
int edge_index[2010][2010];
void fix(int u, int v, int color1, int color2) {
  vertice_colors[u][color2] = true;
  vertice_colors[v][color1] = true;
  vector<pair<int, int>> problem_edges;
  problem_edges.push_back({u, v});
  int _color1 = color1, _color2 = color2;
  while (1) {
    int z = 0;
    for (int j = 0; j < graph[v].size(); ++j) {
      int x = graph[v][j];
      if (edge_color[edge_index[v][x]] == _color2) {
        z = x;
        break;
      }
    }
    if (z)
      problem_edges.push_back({v, z});
    else
      break;
    swap(_color1, _color2);
    v = z;
  }
  vertice_colors[problem_edges[problem_edges.size() - 1].second][_color2] =
      true;
  vertice_colors[problem_edges[problem_edges.size() - 1].second][_color1] =
      false;
  for (auto edge : problem_edges) {
    edge_color[edge_index[edge.first][edge.second]] = color2;
    swap(color1, color2);
  }
}
void recolor(int i) {
  int u = edges[i].first;
  int v = edges[i].second;
  int color1 = 0;
  int color2 = 0;
  for (int j = 1; j <= k and !edge_color[i] and (!color1 or !color2); ++j) {
    if (vertice_colors[u][j] and !vertice_colors[v][j])
      color1 = j;
    else if (!vertice_colors[u][j] and vertice_colors[v][j])
      color2 = j;
  }
  fix(u, v, color1, color2);
}
void color(int i) {
  int u = edges[i].first;
  int v = edges[i].second;
  for (int j = 1; j <= k; ++j) {
    if (!vertice_colors[u][j] and !vertice_colors[v][j]) {
      vertice_colors[u][j] = true;
      vertice_colors[v][j] = true;
      edge_color[i] = j;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, m;
  cin >> a >> b >> m;
  int n = a + b;
  graph = vector<vector<int>>(n + 1);
  edges = vector<pair<int, int>>(m);
  edge_color = vector<int>(m);
  int x, y;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    graph[x].push_back(y + a);
    graph[y + a].push_back(x);
    edges[i] = {x, y + a};
    edge_index[x][y + a] = i;
    edge_index[y + a][x] = i;
  }
  for (int i = 1; i <= n; ++i) k = max(k, (int)graph[i].size());
  cout << k << '\n';
  for (int i = 0; i < m; ++i) {
    color(i);
    if (!edge_color[i]) recolor(i);
  }
  for (int i = 0; i < m; ++i) cout << edge_color[i] << ' ';
  cout << '\n';
  return 0;
}