#include
#define fr(i,n) for(int i=1; i<=n; i++)
#define mp make_pair
#define MXN 1010
using namespace std;
int prev_min_ind[MXN], mincost[MXN], used[MXN];
int pr,tmincost,n,m,k,w;
pair ans[MXN];
char lvl[MXN][15][15];
int main() {
cin>>n>>m>>k>>w;
fr(i,k) fr(j,n) cin>>lvl[i][j];
fr(i,k) mincost[i]=n*m, prev_min_ind[i]=0;
//1 is considered exclusively so i'm assuming prev sent was 1, note that
//this val wouldn't affect answer, you could send any level for first time so
//you could pr any val as far as pr<=k and print this chosen val exclusively
pr=1;
//i need atmost k-1 iterations as i have already chosen 1 vertex but still i need to choose k-1 nodes
//since in each iteration i'll choose at least(exactly) one node so max iterations = k - 1
//this is a very good implementation of prim's algo.
fr(i,k-1){
used[pr] = 1;
int cmincost = 10000, fminind = 0;
//search over all vertices which one gives min cost for sending after pr vertex if this is not used already
fr(x,k) if(!used[x]){
int cst=0;
//find cost of lvl x sending after level pr(if it will be sent in future after 1)
fr(y,n) for(int c=0; ccst){ mincost[x] = cst; prev_min_ind[x]=pr; }
/**
*
* if choosing this x vertex gives me the lowest cost update current min out of all
* note that we are updating prev_min_ind array bcoz this min value might have come from some
* prev iteration of i when it was min in that iteration but in this iteration it became min
* so if this is the case prev_min_ind already have proper value, for second case it must have been
* modified in upper if block
*/
if(mincost[x]