#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e3 + 100, OO = 1e5 + 100, M = 1e9 + 7, P = 6151, SQ = 1300;
vector<int> v[N];
int x[OO], y[OO], wh[N][N], st[N], dlt, c[4], mark[OO];
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m, k;
  cin >> n >> m;
  k = n;
  n += m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    y[i] += k;
    v[x[i]].push_back(i);
    v[y[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) dlt = max(dlt, (int)v[i].size());
  for (int i = 1; i <= m; i++) {
    bool is = false;
    for (int j = 1; j <= dlt; j++) {
      if (wh[x[i]][j] == 0 && wh[y[i]][j] == 0) {
        is = true;
        mark[i] = j;
        break;
      }
      if (wh[x[i]][j] == 0) c[0] = j;
      if (wh[y[i]][j] == 0) c[1] = j;
    }
    if (!is) {
      int t = y[i], pre = i;
      bool b = false;
      mark[i] = c[0], wh[x[i]][c[0]] = i;
      while (true) {
        int nxt = wh[t][c[b]];
        wh[t][c[b]] = pre;
        if (nxt != 0) {
          wh[t][c[b ^ 1]] = nxt;
          mark[nxt] = c[b ^ 1];
          pre = nxt;
          t = x[nxt] + y[nxt] - t;
          b ^= 1;
        } else {
          wh[t][c[b ^ 1]] = 0;
          break;
        }
      }
    } else
      wh[x[i]][mark[i]] = wh[y[i]][mark[i]] = i;
  }
  cout << dlt << endl;
  for (int i = 1; i <= m; i++) cout << mark[i] << " ";
  return 0;
}
