#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
constexpr int MAXN = 1'000'007;
constexpr int INF = 2'000'000'000;
constexpr ll INFF = 1'000'000'000'000'000'000LL;
constexpr ll MOD = 998'244'353;
#define mkp make_pair
#define F first
#define S second
#define pb emplace_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> l(n), r(n);
for (int i = 0; i < n; i++)
cin >> l[i] >> r[i];
vector<vector<int>> contain(n, vector<int>(n));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (l[i] <= l[j] && r[i] >= r[j])
contain[i][j] = 1;
vector<int> used(n);
vector<int> ans(n);
vector<int> li(n), ri(n), lli, rri;
for (int i = 0; i < n; i++)
li[i] = -INF, ri[i] = INF;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
// cout << i << ' ' << j << ' ' << used[j] << '\n';
if (used[j])
continue;
bool ok = 1;
lli = li, rri = ri;
vector<pii> ord;
for (int k = i + 1; k < n; k++) {
if (contain[i][k])
rri[k] = min(rri[k], j - 1);
else if (contain[k][i])
lli[k] = max(lli[k], j + 1);
ord.pb(mkp(lli[k], rri[k]));
}
sort(all(ord));
int idx = 0;
priority_queue<int, vector<int>, greater<int>> pq;
for (int k = 0; k < n; k++) {
if (used[k] || k == j)
continue;
while (idx < sz(ord) && ord[idx].F <= k) {
pq.push(ord[idx].S);
idx++;
}
if (pq.empty() || k > pq.top()) {
ok = 0;
break;
}
pq.pop();
}
if (ok) {
ans[i] = j;
used[j] = 1;
for (int k = i + 1; k < n; k++) {
if (contain[i][k])
ri[k] = min(ri[k], j - 1);
else if (contain[k][i])
li[k] = max(li[k], j + 1);
}
break;
}
}
}
for (int i : ans)
cout << i + 1 << ' ';
cout << '\n';
}
}
/*
- How to come up with solutions? (https://hackmd.io/-3cIVAFSQMC3iJTh9EpszA)
- Play with some small examples.
- Make observations (or random guesses) by intuition.
- Try to find counterexamples of the "observations."
- Find the characteristics of an optimal solution.
- Try to solve simple cases.
- Brute force and print out the results.
- Pick a method (greedy, dp, d&c, ...)
- But DO NOT force algos on problems!
- IF YOU'RE STUCK, TRY SOMETHING ELSE! Make new observations!
- Before writing the solution:
- check TL/ML/correctness of samples/implementation details!
- Pre-submit:
- Did you make a typo when copying a template?
- Test more cases if unsure.
- Write a naive solution and check small cases.
- Submit the correct file.
- Debugging:
- General Debugging:
- Read the whole problem again.
- Think over the algorithm again.
- Go to the toilet.
- Wrong Answer:
- Any possible overflows?
- > `__int128` ?
- Try `-ftrapv` or `#pragma GCC optimize("trapv")`
- Floating point errors?
- > `long double` ?
- turn off math optimizations
- check for `==`, `>=`, `acos(1.000000001)`, etc.
- Did you forget to sort or unique?
- Generate large and worst "corner" cases.
- Check your `m` / `n`, `i` / `j`, `x` / `y` and `<` / `>`.
- Are everything initialized or reset properly?
- Are you sure about the STL thing you are using?
- Read cppreference.
- Print everything and run it on pen and paper.
- Time Limit Exceeded:
- Calculate your time complexity again.
- Does the program actually end?
- Check for `while(q.size())` etc.
- Test the largest cases locally.
- Did you do unnecessary stuff?
- e.g. pass vectors by value
- e.g. `memset` for every test case
- Is your constant factor reasonable?
- Runtime Error:
- Check memory usage.
- Forget to clear or destroy stuff?
- > `vector::shrink_to_fit()`
- Stack overflow?
- Bad pointer / array access?
- Try `-fsanitize=address`
- Division by zero? NaN's?
*/