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
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <typename T>
T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
bool is_down(char x) { return ('a' <= x && x <= 'z'); }
bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
bool is_digit(char x) { return ('0' <= x && x <= '9'); }
const long double pi = 3.141592653589793238462643383279;
const long double log23 = 1.58496250072115618145373894394781;
const long double eps = 1e-8;
const long double zero = 0;
const long long INF = 1e18;
const int COUT = 30;
const int prost = 239;
const long long prost64 = 239;
const int two = 2;
const long long sr = 31;
const int MOD = 1e9 + 7;
const int BIG = 2 * 1e9 + 1;
const int alf = 26;
const int MAX_N = 1e5 + 1;
const int MAX_M = 1001;
const int MAX_T = (1 << 20);
const int BLOCK = trunc(sqrt(MAX_N)) + 1;
const int MAX_LOG = 18;
const int km = (1 << 18);
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int bit_max = 32;
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int bt = 31;
vector<vector<vector<pair<int, int> > > > v;
int a, b, m, ans[MAX_N], d, c1[MAX_M], c2[MAX_M];
vector<pair<int, int> > r;
void fnd(int c, int p, int want, int be) {
  int it = 0;
  for (pair<int, int> t : v[c][p]) {
    if (ans[t.second] == be) break;
    it++;
  }
  if (it == v[c][p].size()) return;
  int to = v[c][p][it].first;
  fnd(1 - c, to, be, want);
  ans[v[c][p][it].second] = want;
}
int main() {
  cin.sync_with_stdio(0);
  cin >> a >> b >> m;
  v.resize(2);
  v[0].resize(a);
  v[1].resize(b);
  for (int i = 0; i < m; i++) {
    int s, f;
    cin >> s >> f;
    s--, f--;
    v[0][s].push_back(make_pair(f, i));
    v[1][f].push_back(make_pair(s, i));
    r.push_back(make_pair(s, f));
  }
  for (int i = 0; i < a; i++) d = max(d, (int)v[0][i].size());
  for (int i = 0; i < b; i++) d = max(d, (int)v[1][i].size());
  cout << d << "\n";
  memset(ans, -1, sizeof(ans));
  for (int t = 0; t < m; t++) {
    int s = r[t].first;
    int f = r[t].second;
    for (int i = 0; i < d; i++) c1[i] = false, c2[i] = false;
    for (pair<int, int> t : v[0][s])
      if (ans[t.second] != -1) c1[ans[t.second]] = true;
    for (pair<int, int> t : v[1][f])
      if (ans[t.second] != -1) c2[ans[t.second]] = true;
    for (int i = 0; i < d; i++) {
      if (!c1[i] && !c2[i]) {
        ans[t] = i;
        break;
      }
    }
    if (ans[t] != -1) continue;
    int u1, u2;
    for (int i = 0; i < d; i++) {
      if (!c1[i]) u1 = i;
      if (!c2[i]) u2 = i;
    }
    fnd(1, f, u2, u1);
    ans[t] = u1;
  }
  for (int i = 0; i < m; i++) cout << ans[i] + 1 << " ";
  return 0;
}
