#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <list>
#include <array>
#include <fstream>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        map<int,  vector<pair<int, int>> > v;
        for (int i = 0; i < n; i++)
        {
            int h, w;
            cin >> h >> w;
            if (h < w) swap(h, w);
            v[h].push_back({ w, i });
        }
        vector<int> ans(n, -1);
        pair<pair<int, int>, int > best = { {0, 1e9}, -1 };
        for (const auto &i : v)
        {
            for (const auto& j : i.second)
            {
                if (best.first.second < j.first) ans[j.second] = best.second + 1;
            }
            for (const auto& j : i.second)
            {
                if (j.first < best.first.second)
                {
                    best = { {i.first, j.first}, j.second };
                }
            }
        }
        for (int i = 0; i < n; i++) cout << ans[i] << " ";
        cout << "\n";
    }
    return 0;
}