#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define inf 1000000000000000LL
#define mod 1000000007LL
#define FOR(i,a,b) for(int i = a; i < b; i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
    uniform_int_distribution <ll> dist(1, 1000000000LL);
    ll n,m,k;
    cin >> n >> m >> k;
    vector <string> l1(n);
    vector <ll> val(n);
    for (int i = 0; i < n; i++){
        val[i] = dist(rng);
    }
    for (int i = 0; i < n; i++) cin >> l1[i];
    auto num = [](char a){
        if (a == 'A'){
            return 0;
        }
        if (a == 'T'){
            return 1;
        }
        if (a == 'G'){
            return 2;
        }
        return 3;
    };
    vector <vector <__int128_t>> cnt(m, vector <__int128_t>(4, 0));
    for (int i =0; i < n; i++){
        for (int j= 0; j < m; j++){
            cnt[j][num(l1[i][j])] += val[i];
        }
    }  
    __int128_t v = 0;
    __int128_t k2 = k;
    for (int i = 0; i < n; i++){
        v += val[i];
    }
    for (int i = 0; i < n; i++){
        __int128_t ves = 0;
        for (int j = 0; j < m; j++){
            for (int x = 0; x < 4; x++){
                if (x != num(l1[i][j])){
                    ves += cnt[j][x];
                }
            }
        }
        if ((v - val[i]) * k2 == ves){
            cout << i + 1 << "\n";
            return;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t = 1;
    while (t--) {
        solve();
    }

    return 0;
}