Problem: There is a developed network of flights between Berland and Beerland. All of them belong to the Berland state company BerAvia. Each flight connects some Berland city with some Beerland city. For each flight airplanes fly in both directions.

Changes are coming to Berland — the state decided to privatize BerAvia, namely, to sell out all flights to t private companies. Each of these companies wants to get the maximal number of flights, so if the Berland flights are sold unevenly, Berland can be accused of partiality. Berland Government decided to sell the flights as evenly as possible between the t companies.

The unevenness of the distribution of flights between companies is calculated as follows. For each city i (both Berland and Beerland) we'll calculate the value of 

<image> where aij is the number of flights from city i, which belong to company j. The sum of wi for all cities in both countries is called the unevenness of the distribution. The distribution with the minimal unevenness is the most even one.

Help the Berland government come up with the most even distribution plan of selling flights.

Input

The first input line contains four integers n, m, k and t (1 ≤ n, m, t ≤ 200;1 ≤ k ≤ 5000), where n, m are the numbers of cities in Berland and Beerland, correspondingly, k is the number of flights between them, and t is the number of private companies. Next k lines describe the flights, one per line, as pairs of positive integers xi, yi (1 ≤ xi ≤ n;1 ≤ yi ≤ m), where xi and yi are the indexes of cities in Berland and Beerland, correspondingly, connected by the i-th flight. There is at most one flight between any pair of cities, each flight connects cities of different countries. The cities in Berland are indexed from 1 to n, and in Beerland — from 1 to m.

Output

Print the unevenness of the sought plan on the first line. On the second line print a sequence of k integers c1, c2, ..., ck (1 ≤ ci ≤ t), where ci is the index of the company that should buy the i-th flight. Assume that the flights are indexed from 1 to k in the order they appear in the input. If there are multiple solutions, print any of them.

Examples

Input

3 5 8 2
1 4
1 3
3 3
1 2
1 1
2 1
1 5
2 2


Output

4
2 1 2 1 2 1 2 2 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 5555;
const long long K = 222;
pair<long long, long long> g[2][N][K];
long long ans[N];
long long deg[2][N], curV[2][N];
long long n, m, k, t;
void dfs(long long part, long long v, const vector<long long> c) {
  long long u = g[part][v][c[part]].first;
  swap(g[part][v][c[part]], g[part][v][c[part ^ 1]]);
  if (u == -1) {
    return;
  }
  dfs(part ^ 1, u, c);
}
void add_edge(long long v, long long u, long long id) {
  long long c1 = -1, c2 = -1;
  auto set_clr = [&]() {
    g[0][v][c2] = {u, id};
    g[1][u][c2] = {v, id};
  };
  for (long long i = 0; i < t; i++) {
    if (g[0][v][i].first == -1) {
      c2 = i;
    }
    if (g[1][u][i].first == -1) {
      c1 = i;
    }
    if (c1 != -1 && c1 == c2) {
      set_clr();
      return;
    }
  }
  assert(c1 != -1 && c2 != -1);
  dfs(1, u, {c1, c2});
  set_clr();
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < N; j++) {
      for (long long k = 0; k < K; k++) {
        g[i][j][k] = {-1, -1};
      }
    }
  }
  cin >> n >> m >> k >> t;
  vector<pair<long long, long long>> edges(k);
  long long cur_size1 = 0, cur_size2 = 0;
  long long res = 0;
  for (long long i = 0; i < k; i++) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    edges[i] = {v, u};
    if (deg[0][v] % t == 0) {
      curV[0][v] = cur_size1++;
    }
    if (deg[1][u] % t == 0) {
      curV[1][u] = cur_size2++;
    }
    deg[0][v]++;
    deg[1][u]++;
    add_edge(curV[0][v], curV[1][u], i);
  }
  for (long long v = 0; v < cur_size1; v++) {
    for (long long clr = 0; clr < t; clr++) {
      if (g[0][v][clr].first == -1) continue;
      ans[g[0][v][clr].second] = clr + 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    res += deg[0][i] % t != 0;
  }
  for (long long i = 0; i < m; i++) {
    res += deg[1][i] % t != 0;
  }
  cout << res << '\n';
  for (long long i = 0; i < k; i++) {
    assert(ans[i] != 0);
    cout << ans[i] << ' ';
  }
  cout << '\n';
}