#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e9 + 7;
const long long int MAX = 1e5;
long long Mu(long long a, long long b, long long mod) {
  long long ans = 0;
  a %= mod;
  while (b) {
    if (b & 1) ans = (ans + a) % mod;
    a = (2 * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long power(long long x, unsigned int y, long long p) {
  int ans = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return ans;
}
int n;
bool dist(long long int a, long long int b, long long int c, long long int d,
          long long int e, long long int f) {
  long long int ab = abs(a - b) + abs(d - e);
  long long int ac = abs(a - c) + abs(d - f);
  long long int cb = abs(b - c) + abs(e - f);
  if (ab == ac + cb)
    return true;
  else
    return false;
}
long long int check(long long int i, long long int j, long long int n,
                    long long int m) {
  if (i >= 0 && j >= 0 && i < n && j < m) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  std::cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(5, 0));
    for (__typeof(0) i = 0; i < n; ++i) {
      for (__typeof(0) j = 0; j < 5; ++j) {
        long long int t;
        cin >> t;
        a[i][j] = t;
      }
    }
    long long int ans = 0, val;
    for (__typeof(1) i = 1; i < n; ++i) {
      val = 0;
      for (__typeof(0) j = 0; j < 5; ++j) {
        if (a[ans][j] < a[i][j]) val++;
      }
      if (val < 5 - val) ans = i;
    }
    long long int f = 0;
    for (__typeof(0) i = 0; i < n; ++i) {
      val = 0;
      if (i == ans) continue;
      for (__typeof(0) j = 0; j < 5; ++j) {
        if (a[ans][j] < a[i][j]) val++;
      }
      if (val < 5 - val) {
        cout << "-1"
             << "\n";
        f = 1;
        break;
      }
    }
    ans++;
    if (f == 0) cout << ans << "\n";
  }
}
