#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long MAXN = 1000000;
using namespace std;
bool comp(vector<int> a, vector<int> b) {
  int count = 0;
  for (int i = 0; i < 5; i++)
    if (a[i] < b[i]) count++;
  if (count >= 3)
    return true;
  else
    return false;
}
void solve() {
  int n;
  cin >> n;
  vector<vector<int> > r(n, vector<int>(6));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) cin >> r[i][j];
    r[i][5] = i;
  }
  if (n == 1) {
    cout << "1\n";
    return;
  }
  sort(r.begin(), r.end(), comp);
  for (int i = 0; i < n - 1; i++) {
    int count = 0;
    for (int j = 0; j < 5; j++) {
      if (r[i + 1][j] < r[0][j]) count++;
    }
    if (count >= 3) {
      cout << "-1\n";
      return;
    }
  }
  cout << r[0][5] + 1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
}
