//#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define infll 0x3f3f3f3f3f3f3f3f
#define il inline
#define re register
#define pb push_back
#define db double
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define MP make_pair
#define lowbit(x) x&(-x)
#define fi first
#define se second
il ll read()
{
	char ch = getchar();
	ll p = 1,data = 0;
	while(ch<'0'||ch>'9')
	{
		if(ch == '-')p = -1;
		ch = getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		data = data*10+(ch^48);
		ch = getchar();
	}
	return p*data;
}
il ll gcd(ll a,ll b)
{
	if(!a || !b) return (!a)?b:a;
	while(b ^= a ^= b ^= a %= b);
	return a;
}
il ll lcm(ll a,ll b)
{
	return a*b/gcd(a,b);
}
void exgcd(ll a, ll b, ll &x,ll &y)
{
	if(!b) x = 1, y = 0;
	else
	{
		exgcd(b, a % b, y, x);
		y -= x * (a / b);
	}
}
il ll qpow(ll a,ll b)
{
	ll r = 1;
	while(b)
	{
		if(b&1)r = a*r;
		a = a*a;
		b>>=1;
	}
	return r;
}
const int mod = 1e9+7,maxn = 2e5+5;
struct node
{
	int x,y,id;
} a[maxn];
int ans[maxn],n;
bool cmp1(node a,node b)
{
	return a.x==b.x?a.y>b.y:a.x>b.x;
}
int dp[maxn],pos[maxn];
int main()
{
	int T = read();
	while(T--)
	{
		n = read();
		for(int i = 1; i <= n; i++)
		{
			a[i].x = read(),a[i].y = read(),ans[i] = -1,a[i].id = i;
			if(a[i].x > a[i].y)
				swap(a[i].x,a[i].y);
			pos[i] = i;	
		}
		sort(a+1,a+1+n,cmp1);
		dp[n+1] = inf,pos[n+1] = n+1;
		for(int i = n; i >= 1; i--)
		{
			if(a[i].y < dp[i+1])
				dp[i] = a[i].y,pos[i] = i;
			else
				dp[i] = dp[i+1],pos[i] = pos[i+1];	
		}
		for(int i = 1; i <= n; i++)
		{
			int l = i+1,r = n,mid,p = 0;
			while(l <= r)
			{
				mid = l+r>>1;
				if(a[mid].x < a[i].x)
					r = mid-1,p = mid;
				else
					l = mid+1;	
			}
			if(dp[p] < a[i].y)
				ans[a[i].id] = a[pos[p]].id;
		}
		for(int i = 1; i <= n; i++)
			printf("%d ",!ans[i]?-1:ans[i]);
		puts("");	
	}
	return 0;
}
/*
4 5
3 4
3 3
*/
