#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T;
  cin >> T;
  while (T--) {
    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 pos = 0;
    for (long long i = 0; i < n; i++) {
      if (i == pos) continue;
      long long count = 0;
      for (long long j = 0; j < 5; j++) {
        if (a[i][j] < a[pos][j]) count++;
      }
      if (count >= 3) pos = i;
    }
    long long ans = pos + 1;
    for (long long i = 0; i < n; i++) {
      long long count = 0;
      if (i == pos) continue;
      for (long long j = 0; j < 5; j++) {
        if (a[pos][j] < a[i][j]) count++;
      }
      if (count < 3) {
        ans = -1;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
