#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) x.size()
#define pii pair<int,int>
#define en '\n'
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
const ll mod=998244353;
//const int mod = 1e9+7;
const int N = 2e5+2;
const int inf = 2e9;
const ll linf = 4e18;
void solve()
{
    int n;
    cin>>n;
    vector<array<int,3>>a(n);
    vector<array<int,2>>p(n);
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        int h,w;
        cin>>h>>w;
        a[i]={min(h,w),max(h,w),i};
    }
    sort(all(a));
    p[0]={a[0][1],0};
    for(int i=1;i<n;i++){
        p[i]=p[i-1];
        if(p[i][0]>a[i][1])p[i]={a[i][1],i};
    }
    ans[a[0][2]]=-1;
    int j=-1;
    for(int i=1;i<n;i++){
        if(a[i][0]!=a[i-1][0])j=i-1;
        if(j==-1||p[j][0]>=a[i][1])ans[a[i][2]]=-1;
        else ans[a[i][2]]=a[p[j][1]][2]+1;
    }
    for(auto u : ans)cout<<u<<' ';
    cout<<en;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    int tt = 1;
    cin >> tt;
    while (tt--){
        solve();
    }
    return 0;
}
