#include <bits/stdc++.h>
using namespace std;
int n, d, k, pre2[101], pre3[101][101];
vector<int> v[100001];
vector<int> operator+(vector<int> a, vector<int> b) {
vector<int> r(d);
for (int i = 0; i < d; i ++) r[i] = a[i] + b[i] % k;
return r;
}
int operator*(vector<int> a, vector<int> b) {
int s = 0;
for (int i = 0; i < d; i ++) s = (s + a[i] * b[i]) % k;
return s;
}
void check(int i) {
for (int j = 0; j < i; j ++) {
if (v[i] * v[j] == 0) {
int x = v[i][d];
int y = v[j][d];
if (x > y) swap(x, y);
cout << x << " " << y << '\n';
return;
}
}
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> d >> k;
for (int i = 0; i < n; i ++) {
v[i] = vector<int>(d + 1);
for (int j = 0; j < d; j ++) {
cin >> v[i][j];
v[i][j] %= k;
}
v[i][d] = i + 1; // index for random shuffle
}
random_shuffle(v, v + n);
if (k == 2) {
for (int i = 0; i < n; i ++) {
vector<int> x = v[i];
int s = 0;
for (int j = 0; j < d; j ++) {
s = (s + x[j] * pre2[j]) % k;
pre2[j] = (pre2[j] + x[j]) % k;
}
if (s % 2 != i % 2) {
check(i);
return 0;
}
}
cout << "-1 -1\n";
} else {
for (int i = 0; i < n; i ++) {
vector<int> x = v[i];
int s = 0;
for (int j = 0; j < d; j ++) {
for (int l = 0; l < d; l ++) {
s = (s + x[j] * x[l] * pre3[j][l]) % k;
pre3[j][l] += x[j] * x[l];
}
}
if (s % 3 != i % 3) {
check(i);
return 0;
}
}
cout << "-1 -1\n";
}
}
/*
input:
3 5 2
1 0 1 0 1
1 1 0 1 0
0 1 0 1 1
output:
2 3
*/
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbiwgZCwgaywgcHJlMlsxMDFdLCBwcmUzWzEwMV1bMTAxXTsKdmVjdG9yPGludD4gdlsxMDAwMDFdOwoKdmVjdG9yPGludD4gb3BlcmF0b3IrKHZlY3Rvcj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