#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e16;
const long long N = 1e6 + 1;
void run() {
  long long n;
  cin >> n;
  long long a[n][5];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 5; j++) cin >> a[i][j];
  }
  long long winner = 0;
  for (long long i = 0; i < n; i++) {
    long long ct = 0;
    for (long long j = 0; j < 5; j++) {
      ct += (a[i][j] < a[winner][j]);
    }
    if (ct >= 3) winner = i;
  }
  for (long long i = 0; i < n; i++) {
    long long ct = 0;
    for (long long j = 0; j < 5; j++) {
      ct += (a[i][j] < a[winner][j]);
    }
    if (ct >= 3) {
      cout << "-1\n";
      return;
    }
  }
  cout << winner + 1 << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long tt = 1;
  cin >> tt;
  while (tt--) run();
  return 0;
}
