#include <iomanip>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include "queue"
//#include <multiset>
#include <map>
#include <utility>
#include <numeric>
#include "random"
#ifndef __clang__
#include <bits/stdc++.h>
#endif
using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long


void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        a[i] = i + 1;
    }
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        if (u < v)
            cnt++;
        else
            cnt--;
    }
    if (cnt < 0)
        reverse(all(a));
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}

signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}
