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;
struct edge {
  int x, y;
  int color = -1;
};
int main() {
  int a, b, m, i, j;
  edge e;
  scanf("%d%d%d", &a, &b, &m);
  vector<edge> edges;
  vector<vector<pair<int, int>>> graph(a + b, vector<pair<int, int>>());
  for (i = 0; i < m; ++i) {
    scanf("%d%d", &e.x, &e.y);
    e.x = e.x - 1;
    e.y = e.y + a - 1;
    edges.push_back(e);
    graph[e.x].push_back(make_pair(e.y, i));
    graph[e.y].push_back(make_pair(e.x, i));
  }
  int colors = 0;
  for (i = 0; i < a + b; ++i) colors = max((int)graph[i].size(), colors);
  printf("%d\n", colors);
  vector<bool> used_color_x(colors, false);
  vector<bool> used_color_y(colors, false);
  for (i = 0; i < m; ++i) {
    for (j = 0; j < colors; ++j) {
      used_color_x[j] = false;
      used_color_y[j] = false;
    }
    for (auto edge : graph[edges[i].x])
      if (edges[edge.second].color > -1)
        used_color_x[edges[edge.second].color] = true;
    for (auto edge : graph[edges[i].y])
      if (edges[edge.second].color > -1)
        used_color_y[edges[edge.second].color] = true;
    int not_used_color = -1;
    for (j = 0; j < colors; ++j)
      if (!used_color_x[j] && !used_color_y[j]) {
        not_used_color = j;
        break;
      }
    if (not_used_color == -1) {
      int color_x, color_y;
      for (j = 0; j < colors; ++j)
        if (used_color_x[j] && !used_color_y[j]) {
          color_x = j;
          break;
        }
      for (j = 0; j < colors; ++j)
        if (!used_color_x[j] && used_color_y[j]) {
          color_y = j;
          break;
        }
      int temp_edge = i;
      int v = edges[i].x;
      edges[temp_edge].color = color_x;
      while (true) {
        int color_x_count = 0;
        for (auto edge : graph[v])
          if (edges[edge.second].color == color_x) color_x_count++;
        if (color_x_count == 2) {
          for (auto edge : graph[v])
            if (edges[edge.second].color == color_x &&
                edge.second != temp_edge) {
              temp_edge = edge.second;
              v = edge.first;
              edges[temp_edge].color = color_y;
              swap(color_x, color_y);
              break;
            }
        } else {
          break;
        }
      }
    } else {
      edges[i].color = not_used_color;
    }
  }
  for (i = 0; i < m; ++i) printf("%d ", edges[i].color + 1);
  return 0;
}