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

void run_test() {
    int N;
    cin >> N;
    vector<array<int, 3>> ar(N);
    for (int i = 0; i < N; i++) {
        cin >> ar[i][0] >> ar[i][1];
        ar[i][2] = i + 1;
        if (ar[i][0] > ar[i][1]) swap(ar[i][0], ar[i][1]);
    }
    sort(ar.begin(), ar.end());
    // for (int i = 0; i < N; i++) cout << ar[i][0] << " " << ar[i][1] << endl;
    // cout << "---" << endl;
    vector<int> res(N, -1);
    int m = -1;
    int a = 0, b = 0;
    while (a < N) {
        while (b < N - 1 && ar[b][0] == ar[b + 1][0]) b++;
        for (int i = a; i <= b; i++) {
            if (m >= 0 && ar[m][1] < ar[i][1]) res[ar[i][2] - 1] = ar[m][2];
        }
        for (int i = a; i <= b; i++) {
            if (m == -1 || ar[i][1] < ar[m][1]) m = i;
        }
        a = ++b;
    }
    for (int i : res) cout << i << " ";
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int T; cin >> T; while (T--)
    run_test();
    return 0;
}