#include<bits/stdc++.h>
using namespace std;
struct node {
    int h, w, min1, max1, num, sum;
};
node a[200010];
int b[200010];
bool cmp(node a1, node a2) {
    if (a1.max1 != a2.max1)
        return a1.max1 < a2.max1;
    return a1.sum < a2.sum;
}
int main() {
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i].h >> a[i].w;
            a[i].num = i;
            a[i].min1 = min(a[i].h, a[i].w);
            a[i].max1 = max(a[i].h, a[i].w);
            a[i].sum = a[i].h + a[i].w;
        }
        sort(a + 1, a + 1 + n, cmp);
        b[a[1].num] = -1;
        int l = a[1].min1, r = a[1].max1, num = a[1].num;
        int l_ = a[1].min1, r_ = a[1].max1, num_ = a[1].num;
        for (int i = 2; i <= n; i++) {
            if (a[i].min1 > l && a[i].max1 > r) {
                b[a[i].num] = num;
            }
            else if (a[i].min1 > l_ && a[i].max1 > r_) {
                b[a[i].num] = num_;
            }
            else if (a[i].min1 < l) {
                b[a[i].num] = -1;
                swap(l, l_);
                swap(r, r_);
                swap(num, num_);
                l = a[i].min1;
                r = a[i].max1;
                num = a[i].num;
            }
            else {
                b[a[i].num] = -1;
            }
        }
        for (int i = 1; i <= n; i++) {
            cout << b[i] << " ";
        }
        cout << endl;
    }
    return 0;
}