#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

typedef pair<int,int> pii;
vector<pii> A;
vector<pair<pii,int>> A_sorted;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int t; cin >> t;
	while(t--)
	{
		int n; cin >> n;
		A = vector<pii>(n);
		for(int i = 0; i < n; i++)
		{
			int h,w;
			cin >> h >> w;
			if(h < w) swap(h,w);
			A[i] = make_pair(h,w);
		}
		
		A_sorted = vector<pair<pii,int>>(n);
		for(int i = 0; i < n; i++)
		{
			A_sorted[i].first = A[i];
			A_sorted[i].second = i;
		}
		
		sort(A_sorted.begin(),A_sorted.end());
		
		vector<int> ans(n,-1);
		
		int smallest_h;
		int smallest_w;
		int smallest_index;
		
		int cand_smallest_h = A_sorted[0].first.first;
		int cand_smallest_w = A_sorted[0].first.second;
		int cand_smallest_index = A_sorted[0].second;
		
		for(int i = 0; i < n; i++)
		{
			if(A_sorted[0].first.first == A_sorted[i].first.first) continue;
			
			int prev_h = A_sorted[i-1].first.first;
			int now_h = A_sorted[i].first.first;
			int now_w = A_sorted[i].first.second;
			int now_index = A_sorted[i].second;
			
			if(prev_h != now_h)
			{
				smallest_h = cand_smallest_h;
				smallest_w = cand_smallest_w;
				smallest_index = cand_smallest_index;
				
				if(smallest_w > now_w)
				{
					cand_smallest_h = now_h;
					cand_smallest_w = now_w;
					cand_smallest_index = now_index;
				}
			}
			
			if(smallest_w < now_w)
				ans[now_index] = smallest_index;
		}
		
		for(int i = 0; i < n; i++)
		{
			if(ans[i] != -1) cout << ans[i] + 1 << ' ';
			else cout << -1 << ' ';
		}
		cout << '\n';
	}
	
	return 0;
}