#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long v[n][5];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 5; j++) cin >> v[i][j];
  }
  if (n == 1) {
    cout << "1\n";
    return;
  }
  long long orz = 0;
  for (long long i = 1; i < n; i++) {
    long long cnt = 0;
    for (long long l = 0; l < 5; l++) {
      if (v[i][l] < v[orz][l]) cnt++;
    }
    if (cnt >= 3)
      orz = i;
    else
      continue;
  }
  bool clash = 0;
  for (long long i = 0; i < n; i++) {
    long long cnt = 0;
    if (orz != i) {
      for (long long l = 0; l < 5; l++) {
        if (v[i][l] < v[orz][l]) cnt++;
      }
      if (cnt >= 3) {
        clash = 1;
        break;
      }
    }
  }
  if (clash)
    cout << "-1\n";
  else
    cout << orz + 1 << endl;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
