#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <vector>

using namespace std;

const char *secret = "8a87120bd5122e261c90";

class Sets {
private:
    int compare_calls;
    int weights_id;
public:
    long long **sets;
    int n, k, T;
    int get_compare_calls() { return compare_calls; }
    void read() {
        compare_calls = 0;
        assert(scanf("%d %d %d %d", &n, &k, &T, &weights_id) == 4);
        sets = new long long*[k];
        for (int i = 0; i < k; i++) {
            sets[i] = new long long[n];
            for (int j = 0; j < n; j++)
                assert(scanf("%lld", &sets[i][j]) == 1);
        }
    }
    int compare(int first, int second) {
        compare_calls++;
        if (!(popcount((unsigned int) first) + popcount((unsigned int) second) <= n &&
                    (first & second) == 0))
        {
            printf("%s\n-2\n", secret);
            exit(0);
        }
        long long sum = 0;
        for (int i = 0; i < n; i++)
            if ((first >> i) & 1)
                sum += sets[weights_id][i];
        for (int i = 0; i < n; i++)
            if ((second >> i) & 1)
                sum -= sets[weights_id][i];
        return (sum == 0 ? 0 : (sum < 0 ? -1 : 1));
    }
private:
    static int popcount(unsigned int a) {
        int res;
        for (res = 0; a; res += (a & 1), a >>= 1);
        return res;
    }
};

Sets s;

int identify_set(int, int, long long**);

int main(){
    s.read();    
    int ans = identify_set(s.n, s.k, s.sets);
    printf("%s\n%d\n%d\n", secret, ans, s.get_compare_calls());
}

#define MOD (1000000007)
#define EPS (1e-9)
#define INF (2117117117)
#define LLINF (2117117117117117117LL)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define sqr(a) ((a) * (a))
#define sz(a) ((int) (a).size())

typedef unsigned int uint;
typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

using namespace std;

const int MAXN = 540000;

int res[MAXN], resn;

inline int my_compare(int i, int j, llong *sets, int n)
{
    llong sum = 0;
    for (int t = 0; t < n; t++)
    {
        if ((i >> t) & 1)
            sum += sets[t];
        if ((j >> t) & 1)
            sum -= sets[t];
    }
    return (sum == 0 ? 0 : (sum < 0 ? -1 : 1));
}

int identify_set(int n, int k, llong **sets)
{
    if (k == 1)
        return 0;
    if (n == 1)
        return -1;

    resn = 0;
    for (int i = 0; i < (1 << n); i++)
    {
        for (int j = i; j; j = ((j - 1) & i))
            res[resn++] = s.compare(j, j ^ i);
        res[resn++] = s.compare(0, i);
    }

    vector<int> candidates;
    for (int t = 0; t < k; t++)
    {
        bool f = true;
        int cur = 0;
        for (int i = 0; i < (1 << n); i++)
        {
            for (int j = i; j; j = ((j - 1) & i))
                f &= (res[cur++] == my_compare(j, j ^ i, sets[t], n));
            f &= (res[cur++] == my_compare(0, i, sets[t], n));
        }
        if (f)
            candidates.pb(t);
    }
    return (sz(candidates) == 1 ? candidates[0] : -1);
}
