#include <bits/stdc++.h>
#include <cstring>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=2e5+100;
const int maxn=1e6;
const int MAXL=sqrt(1e5)+1;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n;
int h[N],w[N];
int f[2*N],s[2*N];
vector<int>ve;
void solve()
{
    n=read();
    ve.clear();
    for(int i=1;i<=n;i++)
    {
        h[i]=read();
        w[i]=read();
        ve.push_back(h[i]);
        ve.push_back(w[i]);
    }
    sort(ve.begin(),ve.end());
    ve.erase(unique(ve.begin(),ve.end()),ve.end());
    for(int i=1;i<=n;i++)
    {
        h[i]=lower_bound(ve.begin(),ve.end(),h[i])-ve.begin();
        w[i]=lower_bound(ve.begin(),ve.end(),w[i])-ve.begin();
        h[i]++; w[i]++;
    }
    int cnt=ve.size();
    for(int i=0;i<=cnt;i++)
        f[i]=INT_MAX;
    for(int i=1;i<=n;i++)
    {
        if(f[h[i]]>w[i])
        {
            f[h[i]]=w[i];
            s[h[i]]=i;
        }
        if(f[w[i]]>h[i])
        {
            f[w[i]]=h[i];
            s[w[i]]=i;
        }
    }
    int ans=INT_MAX;
    for(int i=2;i<=cnt;i++)
    {
        if(f[i]>f[i-1])
        {
            f[i]=f[i-1];
            s[i]=s[i-1];
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(f[h[i]-1]<w[i])
            printf("%d ",s[h[i]-1]);
        else    printf("-1 ");
    }
    printf("\n");

}


int main()
{
    int T=1;
    scanf("%d",&T);
    //T=1;
    //cout<<tot<<endl;
    int tt=0;
    while(T--)

    {
        //if(n==0)    break;
        //printf("Case %d: ",++tt);
        solve();
    }

    return 0;

}
