#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;

const int INF = 2e9;

struct Person
{
    int i, h, w;
};

int main()
{
    int T;
    cin >> T;

    while(T--)
    {
        int n;
        scanf("%d", &n);

        vector <Person> a(n);
        for(int i = 0; i < n; i++)
            scanf("%d%d", &a[i].h, &a[i].w), a[i].i = i;

        vector <Person> H = a, W = a;

        sort(H.begin(), H.end(), [](const Person& x, const Person& y) {
             return x.h < y.h;
        });

        sort(W.begin(), W.end(), [](const Person& x, const Person& y) {
             return x.w < y.w;
        });

        vector <int> Hh(n);
        for(int i = 0; i < n; i++)
            Hh[i] = H[i].h;

        vector <int> Ww(n);
        for(int i = 0; i < n; i++)
            Ww[i] = W[i].w;

        vector <int> prefixMinHw(n + 1, -1);
        for(int i = 0; i < n; i++)
        {
            int j = prefixMinHw[i];
            prefixMinHw[i + 1] = j;
            if(j == -1 || H[i].w < a[j].w)
                prefixMinHw[i + 1] = H[i].i;
        }

        vector <int> prefixMinWh(n + 1, -1);
        for(int i = 0; i < n; i++)
        {
            int j = prefixMinWh[i];
            prefixMinWh[i + 1] = j;
            if(j == -1 || W[i].h < a[j].h)
                prefixMinWh[i + 1] = W[i].i;
        }

        vector <int> answer(n, -1);
        for(int i = 0; i < n; i++)
        {
            int h = a[i].h, w = a[i].w;
            for(int r = 0; r < 2; r++)
            {
                int j = lower_bound(Hh.begin(), Hh.end(), h) - Hh.begin();
                j = prefixMinHw[j];
                if(j != -1 && a[j].w < w)
                    answer[i] = j + 1;

                j = lower_bound(Ww.begin(), Ww.end(), w) - Ww.begin();
                j = prefixMinWh[j];
                if(j != -1 && a[j].h < h)
                    answer[i] = j + 1;

                swap(h, w);
            }
        }

        for(int x : answer)
            printf("%d ", x);
        puts("");
    }
}
