#include <bits/stdc++.h>
#define sz              size()
#define pb              push_back
#define Fr              first
#define Sc              second
#define Log2(x)         (31^__builtin_clz(x))
#define endl            "\n"
#define int             ll
typedef long long ll;
using namespace std;
int T;
int n;
int ans[200200];
pair<int, pair<int, int>> A[200200];
bool ok(int mid, int h, int w) {
    int midH = A[mid].Fr;
    int midW = A[mid].Sc.Fr;
    return ((h > midH && w > midW) || (w > midH && h > midW));
}
int32_t main() {
    ios::sync_with_stdio( false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> T;
    while(T--) {
      cin >> n;
      for(int i = 0 ; i < n ; i++){
        int w, h;
        cin >> h >> w;
        A[i].Sc.Sc = i;
        ans[i] = -1;
        A[i].Fr = min(h, w);
        A[i].Sc.Fr = max(h, w);
      }
      sort(A, A + n);
      pair<int, pair<int, int>> mn = A[0];

      for(int i = 0, j = 0 ; i < n ; i++) {
        while(j < n &&A[j].Fr < A[i].Fr &&  mn.Fr < A[i].Fr) {
            if(mn.Sc.Fr > A[j].Sc.Fr) {
                mn = A[j];
            }
            j++;
        }
        if(mn.Fr < A[i].Fr && mn.Sc.Fr < A[i].Sc.Fr)
            ans[A[i].Sc.Sc] = mn.Sc.Sc + 1;
      }
      for(int i = 0 ; i < n ; i++)
        cout << ans[i] << " ";
      cout << endl;
    }
}
