#include <bits/stdc++.h>
int c[1010][1010];
char a[1010][11][11];
int dis[1010], u[1010], f[1010];
int main() {
  int n, m, nn, w, i, j, k, p, q, x;
  scanf("%d%d%d%d", &n, &m, &nn, &w);
  for (k = 0; k < nn; k++) {
    for (i = 0; i < n; i++) scanf("%s", a[k][i]);
  }
  for (p = 0; p < nn; p++) {
    for (q = p + 1; q < nn; q++) {
      c[p][q] = 0;
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          if (a[p][i][j] != a[q][i][j]) c[p][q]++;
        }
      }
      c[p][q] = c[q][p] = c[p][q] * w;
    }
  }
  for (i = 0; i < nn; i++) {
    dis[i] = n * m;
    f[i] = -1;
  }
  int ans = 0;
  for (k = 0; k < nn; k++) {
    x = -1;
    for (i = 0; i < nn; i++) {
      if (u[i] == 0 && (x < 0 || dis[x] > dis[i])) x = i;
    }
    u[x] = 1;
    ans += dis[x];
    for (i = 0; i < nn; i++) {
      if (u[i] == 0 && dis[i] > c[x][i]) {
        dis[i] = c[x][i];
        f[i] = x;
      }
    }
  }
  printf("%d\n", ans);
  for (i = 0; i < nn; i++) u[i] = 0;
  ans = 0;
  while (ans < nn) {
    for (i = 0; i < nn; i++) {
      if (u[i] == 0) {
        if (f[i] < 0 || u[f[i]]) {
          u[i] = 1;
          ans++;
          printf("%d %d\n", i + 1, f[i] + 1);
        }
      }
    }
  }
  return 0;
}
