#include <bits/stdc++.h>
using namespace std;

class triplet{
    public:
    int first;
    int second;
    int third;
};

bool cmp1(triplet t1, triplet t2){
    return t1.first > t2.first;
}

bool cmp2(triplet t1, triplet t2){
    return t1.second > t2.second;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        triplet *a = new triplet[n];
        triplet *heightDec = new triplet[n];
        triplet *widthDec = new triplet[n];
        for(int i=0;i<n;i++){
            cin >> a[i].first >> a[i].second;
            a[i].third = i + 1;
            heightDec[i] = a[i];
            widthDec[i] = a[i];
        }

        sort(heightDec,heightDec+n,cmp1);
        sort(widthDec,widthDec+n,cmp2);
        pair <int,int> *minW = new pair<int,int>[n];
        pair <int,int> *minH = new pair<int,int>[n];
        int minWidth = heightDec[n-1].second;
        int minHeight = widthDec[n-1].first;
        minW[n-1] = make_pair(minWidth,heightDec[n-1].third);
        minH[n-1] = make_pair(minHeight,widthDec[n-1].third);
        for(int i=(n-2);i>=0;i--){
            if(heightDec[i].second < minWidth){
                minWidth = heightDec[i].second;
                minW[i] = make_pair(minWidth,heightDec[i].third);
            }
            else{
                minW[i] = minW[i+1];
            }

            if(widthDec[i].first < minHeight){
                minHeight = widthDec[i].first;
                minH[i] = make_pair(minHeight,widthDec[i].third);
            }
            else{
                minH[i] = minH[i+1];
            }   
        }
        /*cout << "heightDec : \n";
        for(int i=0;i<n;i++){
            cout << heightDec[i].first << " " << heightDec[i].second << " " << heightDec[i].third << endl;
        }

         cout << "widthDec : \n";
        for(int i=0;i<n;i++){
            cout << widthDec[i].first << " " << widthDec[i].second << " " << widthDec[i].third << endl;
        }


        cout << "minW : \n";
        for(int i=0;i<n;i++){
            cout << minW[i].first << " " << minW[i].second << endl;
        }
        cout << "minH : \n";
        for(int i=0;i<n;i++){
            cout << minH[i].first << " " << minH[i].second << endl;
        }*/
        for(int i=0;i<n;i++){
            int currH = a[i].first;
            int currW = a[i].second;
            int idx = -1;
            //In heightDec
            int l = 0;
            int h = n-1;
            int ansidx = -1;

            while(l <= h){
                int mid = l + (h-l)/2;
                if(heightDec[mid].first < currH){
                    ansidx = mid;
                    h = mid - 1;
                }
                else{
                    l = mid + 1;
                }
            }
            if(ansidx!=-1){
                if(minW[ansidx].first < currW){
                    idx = minW[ansidx].second;
                }
            }
            if(idx == -1){
            //In WidthDec
            l = 0;
            h = n-1;
            ansidx = -1;
            while(l <= h){
                int mid = l + (h-l)/2;
                if(widthDec[mid].second < currH){
                    ansidx = mid;
                    h = mid - 1;
                }
                else{
                    l = mid + 1;
                }
            }

            if(ansidx!=-1){
                if(minH[ansidx].first < currW){
                    idx = minH[ansidx].second;
                }
            }
        }
        cout << idx << " ";
    }
    cout << endl;
    delete []a;
    delete []heightDec;
    delete []widthDec;
    delete []minW;
    delete []minH;


}

    return 0;
}