#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MX = 2e5 + 100;

map<int,int> mp;
int ans[MX];
int N;
int arr[MX];
vector<pair<pair<int,int>,  int>  > v;

void solve()
{
    mp.clear();
    v.clear();
    memset(ans, 0, sizeof ans);
    scanf("%d", &N);
    for(int i=0; i<N; i++)
    {
        int h, w;
        scanf("%d%d", &h, &w);
        if(h > w)
        {
            swap(h, w);
        }
        v.push_back({{h, w}, i});
    }

    sort(v.begin(), v.end());

    for(int i=0; i<v.size(); i++)
    {
        int h = v[i].first.first;
        int w = v[i].first.second;

        int j = i;
        while(j < N && v[j].first.first == h)
        {
            int hh = v[j].first.first;
            int ww = v[j].first.second;

            map<int,int>::iterator it = mp.lower_bound(ww);
            if(it != mp.begin())
            {
                it--;
            }
            else
            {
                j++;
                continue;
            }


            if(it != mp.end())
            {
                int idx = it->second;

                ans[v[j].second] = v[idx].second + 1;
            }

            ++j;
        }

        for(int k=i; k<j; k++)
        {
            int hh = v[k].first.first;
            int ww = v[k].first.second;
            mp[ww] = k;
        }

        i = j-1;

    }

    for(int i=0; i<N; i++)
    {
        if(ans[i] == 0) ans[i] = -1;
        cout<<ans[i]<<" ";
    }
    cout<<"\n";
}

/*
1
3
3 4
5 4
3 3

1
3
1 3
2 2
3 1
*/
int main()
{

    int T = 1;
    scanf("%d", &T);
    while(T--)
    {
        solve();
    }
    return 0;
}
