import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint, std.string;

void read(S...)(ref S args) {
  auto input = readln.split;
  assert(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

alias Ath = int[];

bool sup(Ath a, Ath b) {
  int t = 0;
  foreach (i; 0 .. 5) {
    if (a[i] < b[i]) t++;
  }
  
  return t >= 3;
}

void main() {
  int T;
  read(T);

  while (T--) {
    int n;
    read(n);
    Ath[] arr;
    foreach (i; 0 .. n) {
      arr ~= list!int;
    }
    
    auto rem = iota(n).array;
    
    while (rem.length != 1) {
      int[] rem2;
      
      for (int i = 0; i < rem.length; i += 2) {
        if (i == rem.length - 1) {
          rem2 ~= rem[i];
        } else {
          if (sup(arr[rem[i]], arr[rem[i + 1]])) {
            rem2 ~= rem[i];
          } else {
            rem2 ~= rem[i + 1];
          }
        }
      }
      
      rem = rem2;
    }
    
    int target = rem.front;
    bool yes = true;
    foreach (i, a; arr) {
      if (i != target && !sup(arr[target], a)) {
        yes = false;
      }
    }
    
    if (!yes) {
      writeln(-1);
    } else {
      writeln(target + 1);
    }
  }
}

