#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
int main(){
    int TC;
    cin >> TC;
    while(TC--){
        int N, le, ri, now;
        cin >> N;
        pair< pair<int, int> , int> rec[N];
        for(int i=0; i<N; i++){
            cin >> le >> ri;
            if(le<ri)
                swap(le, ri);
            rec[i]=mp(mp(le, ri), i);
        }
        sort(rec, rec+N);
        int H[N], ans[N];
        pair<int, int> W[N];
        H[0]=rec[0].fi.fi; W[0]=mp(rec[0].fi.se, 0);
        for(int i=1; i<N; i++){
            H[i]=rec[i].fi.fi;
            if(rec[i].fi.se<W[i-1].fi)
                W[i]=mp(rec[i].fi.se, i);
            else
                W[i]=W[i-1];
        }
        for(int i=0; i<N; i++){
            now=-1;

            le=lower_bound(H, H+N, H[i])-H-1;
            if(le>=0 && H[W[le].se]<H[i] && W[le].fi<rec[i].fi.se)
                now=rec[W[le].se].se+1;

            ans[rec[i].se]=now;
        }
        for(int i=0; i<N; i++)
            cout << ans[i] << ' ';
        cout << endl;
    }
}
