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 maxn = 2100;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-9;
inline int sgn(double a) { return a < -eps ? -1 : a > eps; }
const int A = 1000;
int a, b, m;
int ans;
struct edge {
  int u;
  int v;
  int col;
  edge(int a = 0, int b = 0, int c = 0) : u(a), v(b), col(c) {}
};
vector<edge> e;
set<int> usable_col[maxn];
vector<int> v[maxn];
int use_col[maxn][maxn];
int find_col(int u, int ei, int pre_col) {
  int v;
  if (e[ei].u == u)
    v = e[ei].v;
  else
    v = e[ei].u;
  for (int col : usable_col[u]) {
    if (col != pre_col && usable_col[v].count(col)) return col;
  }
  for (int col : usable_col[u]) {
    if (col != pre_col) return col;
  }
  return -1;
}
void delate_col(int u, int col) {
  if (col == -1) return;
  if (use_col[u][col] == 0) return;
  use_col[u][col] = 0;
  usable_col[u].insert(col);
}
void add_col(int u, int col, int ei) {
  if (use_col[u][col] != 0) return;
  use_col[u][col] = ei;
  auto it = usable_col[u].find(col);
  if (it != usable_col[u].end()) usable_col[u].erase(it);
}
void color_edge(int u, int ei, int col) {
  int pre_col = e[ei].col;
  if (pre_col == col) return;
  e[ei].col = col;
  delate_col(u, pre_col);
  add_col(u, col, ei);
  int v;
  if (e[ei].u == u)
    v = e[ei].v;
  else
    v = e[ei].u;
  delate_col(v, pre_col);
  if (use_col[v][col] != 0) {
    int x = use_col[v][col];
    int tcol = pre_col;
    if (pre_col == -1) {
      tcol = find_col(v, x, col);
    }
    color_edge(v, x, tcol);
  }
  add_col(v, col, ei);
}
int main() {
  scanf("%d%d%d", &a, &b, &m);
  int x, y;
  for (int i = 0; i <= b + A; i++) {
    usable_col[i].clear();
  }
  e.push_back(edge(-1, -1, -1));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    y += A;
    e.push_back(edge(x, y, -1));
    v[x].push_back(i);
    v[y].push_back(i);
  }
  for (int j = 1; j <= a; j++) {
    ans = max((int)v[j].size(), ans);
  }
  for (int j = 1; j <= b; j++) {
    ans = max((int)v[j + A].size(), ans);
  }
  for (int i = 1; i <= ans; i++) {
    for (int j = 1; j <= a; j++) {
      usable_col[j].insert(i);
    }
    for (int j = 1; j <= b; j++) {
      usable_col[j + A].insert(i);
    }
  }
  for (int i = 1; i <= a; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      int t = v[i][j];
      if (e[t].col == -1) {
        color_edge(i, t, find_col(i, t, -1));
      }
    }
  }
  for (int i = A + 1; i <= A + b; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      int t = v[i][j];
      if (e[t].col == -1) {
        color_edge(i, t, find_col(i, t, -1));
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= m; i++) {
    printf("%d ", e[i].col);
  }
  return 0;
}