/**
 *    author:  [itmo] enot110
 *    created: 2024-11-10 13:38:21
**/
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */


int main()
{
    #ifdef home
        assert(freopen("in", "r", stdin));
        // assert(freopen("out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        int inc = 0;
        int dec = 0;
        forn(i, m)
        {
            int x, y;
            scanf("%d%d", &x, &y);
            if (x < y) inc++;
            else dec++;
        }
        if (inc >= dec) forn(i, n) printf("%d%c", i + 1, " \n"[i + 1 == n]);
        else forn(i, n) printf("%d%c", n - i, " \n"[i + 1 == n]);
    }


    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}