#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000007; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int n, m, q;
int t;
int P[1012];
char A[1012][12][12];
pair<int, pair<int, int> > E[1012 * 1012];
vector<pair<int, int> > R[1012];
int B[1012];
int root(int i) {
  if (P[i] == i) return i;
  return P[i] = root(P[i]);
}
void dfs(int i) {
  B[i] = 1;
  int j, k;
  for (k = (0); k < (R[i].size()); ++k) {
    j = R[i][k].first;
    if (B[j]) continue;
    printf((firstout) ? "%"
                        "d"
                      : " %"
                        "d",
           (j + 1)),
        firstout = 0;
    if (R[i][k].second == t)
      printf((firstout) ? "%"
                          "d"
                        : " %"
                          "d",
             (0)),
          firstout = 0;
    else
      printf((firstout) ? "%"
                          "d"
                        : " %"
                          "d",
             (i + 1)),
          firstout = 0;
    printf("\n"), firstout = 1;
    dfs(j);
  }
}
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    int x;
    scanf(
        "%"
        "d",
        &(m));
    scanf(
        "%"
        "d",
        &(q));
    scanf(
        "%"
        "d",
        &(x));
    for (k = (0); k < (q); ++k) {
      for (i = (0); i < (n); ++i)
        scanf(
            "%"
            "s",
            &(A[k][i]));
    }
    int qq = 0;
    int kk;
    for (k = (0); k < (q); ++k)
      for (kk = (k + 1); kk < (q); ++kk) {
        int r = 0;
        for (i = (0); i < (n); ++i)
          for (j = (0); j < (m); ++j) r += A[k][i][j] != A[kk][i][j];
        E[qq++] = make_pair(min(r * x, n * m), make_pair(k, kk));
      }
    t = n * m;
    n = q;
    m = qq;
    for (i = (0); i < (n); ++i) P[i] = i, R[i].clear();
    sort(E, E + m);
    int res = 0;
    for (k = (0); k < (m); ++k) {
      i = E[k].second.first;
      j = E[k].second.second;
      int ii = root(i);
      int jj = root(j);
      if (ii != jj) {
        a = E[k].first;
        res += a;
        R[i].push_back(make_pair(j, a));
        R[j].push_back(make_pair(i, a));
        P[ii] = jj;
      }
    }
    res += t;
    printf(
        "%"
        "d",
        (res));
    printf("\n"), firstout = 1;
    printf((firstout) ? "%"
                        "d"
                      : " %"
                        "d",
           (1)),
        firstout = 0;
    printf((firstout) ? "%"
                        "d"
                      : " %"
                        "d",
           (0)),
        firstout = 0;
    printf("\n"), firstout = 1;
    for (i = (0); i < (n); ++i) B[i] = 0;
    dfs(0);
  }
  return 0;
}
