#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9;
long long int power(long long int a, long long int b) {
  long long int p = 1;
  a %= mod;
  while (b > 0) {
    if (b & 1) p = (p * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return p;
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n][5];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < 5; j++) cin >> a[i][j];
  }
  long long int gold = 0;
  for (long long int i = 1; i < n; i++) {
    long long int c = 0;
    for (long long int j = 0; j < 5; j++)
      if (a[i][j] < a[gold][j]) c += 1;
    if (c >= 3) gold = i;
  }
  for (long long int i = 0; i < n; i++) {
    long long int c = 0;
    for (long long int j = 0; j < 5; j++)
      if (a[i][j] < a[gold][j]) c += 1;
    if (c >= 3) {
      gold = -2;
      break;
    }
  }
  cout << gold + 1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
