public P366E() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        K = sc.nextInt();
        int s = sc.nextInt();
        
        upper = new int[K];
        lower = new int[K];
        
        highest = new int[M][K];
        lowest  = new int[M][K];
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < K; j++) {
                highest[i][j] = lowest[i][j] = -1;
            }
        }
        
        sc.nextLine();
        for (int i = N-1; i >= 0; i--) {
            StringTokenizer st = new StringTokenizer(sc.nextLine());
            for (int j = 0; j < M; j++) {
                int a = Integer.parseInt(st.nextToken()) - 1;
                if (highest[j][a] == -1) highest[j][a] = i;
                lowest[j][a] = i;
            }
        }
        
        neighbor = new boolean[K][K];
        dist     = new int[K][K];
        int[] q = new int[s];
        for (int i = 0; i < s; i++) {
            q[i] = sc.nextInt() - 1;
        }
        for (int i = 1; i < s; i++) {
            int a = q[i-1];
            int b = q[i];
            if (a < b) neighbor[a][b] = true;
            else       neighbor[b][a] = true;
        }
    }