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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int h[n + 7], w[n + 7];

        map<int, vector<int>> mp;
        for (int i = 1; i <= n; ++i) {
            cin >> h[i] >> w[i];
            if (h[i] > w[i])
                swap(h[i], w[i]);
            mp[h[i]].emplace_back(i);
        }

        int mn = 1 << 30, ret = -1;
        int ans[n + 7];
        for (auto i : mp) {
            for (int j : i.second) {
                if (mn < w[j])
                    ans[j] = ret;
                else
                    ans[j] = -1;
            }
            for (int j : i.second)
                if (w[j] < mn)
                    mn = w[j], ret = j;
        }

        for (int i = 1; i <= n; ++i)
            cout << ans[i] << " ";
        cout << "\n";
    }
}
