#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e4 + 7;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 7;
const long long mlog = 20;
const long long SQ = 400;
long long r[maxn][5];
bool isSuper(long long x, long long y) {
  long long cnt = 0;
  for (long long i = 0; i < 5; i++)
    if (r[x][i] < r[y][i]) cnt++;
  return cnt >= 3;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++)
      for (long long j = 0; j < 5; j++) cin >> r[i][j];
    long long mx = 1;
    for (long long i = 2; i <= n; i++) {
      if (isSuper(mx, i)) continue;
      mx = i;
    }
    bool flag = true;
    for (long long i = 1; i <= n; i++)
      if (i != mx)
        if (!isSuper(mx, i)) flag = false;
    cout << (flag ? mx : -1) << "\n";
  }
  return 0;
}
