#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> ranks(n, vector<int>(5));
  for (int j = 0; j < n; j++)
    for (int i = 0; i < 5; i++) cin >> ranks[j][i];
  ;
  int best = 0;
  for (int i = 1; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < 5; j++) {
      if (ranks[i][j] < ranks[best][j]) cnt++;
    }
    if (cnt >= 3) best = i;
  }
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < 5; j++) {
      if (ranks[i][j] < ranks[best][j]) cnt++;
    }
    if (cnt >= 3) {
      cout << "-1\n";
      return;
    }
  }
  cout << (best + 1) << "\n";
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
