#include <bits/stdc++.h>
using namespace std;
void read (int &x) {
    char ch = getchar(); int f = 0; x = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    if (f) x = -x;
} const int N = 5e5 + 5;
int n, m, now, c[N], a[N], b[N], tp, st[N], num[N];
set<int> e[N]; vector<int> g[N];
void add (int u, int v) { e[u].insert (v), ++c[v]; }
void link (int u, int v) { g[u].push_back (v), ++num[v]; }
/* 构造补图中的 "star" 形————>构造补图的生成树（森立）————>从树中抽取 star */
vector<int> t[N]; int p, star[N], bl[N], sz[N];
void dfs (int u, int la) {
    st[++tp] = u;
    if (!bl[u]) {
        int tag = 0;
        for (int v : g[u]) if (!bl[v]) tag = 1;
        if (tag) {
            bl[u] = ++p, star[p] = u; sz[p] = 1;
            for (int v : g[u]) if (!bl[v]) bl[v] = p, ++sz[p];
        } else {
            int v = g[u][0];
            if (sz[bl[v]] > 2) {
                --sz[bl[v]], bl[v] = bl[u] = ++p, star[p] = u, sz[p] = 2;
            } else {
                bl[u] = bl[v], star[bl[v]] = v, ++sz[bl[v]];
                for (int o : g[v]) if (!bl[o]) bl[o] = bl[v], ++sz[bl[v]];
            }
        }
    }
    for (int v : g[u]) if (v != la) dfs (v, u);
}
void work () {
    for (int i = 1; i <= p; ++i) t[i].clear();
    for (int i = 1; i <= tp; ++i)
        if (st[i] != star[bl[st[i]]]) t[bl[st[i]]].push_back (st[i]);
    for (int i = 1; i <= p; ++i) {
        int s = 0;
        for (int j : t[i]) a[j] = now + s, b[j] = now + s + 1, ++s;
        a[star[i]] = now + s, b[star[i]] = now; now += s + 1; t[i].clear();
    }
}
int fa[N];
int get (int x) { return fa[x] == x ? x : fa[x] = get (fa[x]); }
void merge (int x, int y) { fa[get (x)] = get (y); }
signed main() {
    int T; read (T);
    for (int TT = 1; TT <= T; ++TT) {
        read (n), read (m); now = 1;
        // if (TT == 8) printf ("%d %d\n", n, m);
        for (int i = 1; i <= n; ++i)
            e[i].clear(), c[i] = num[i] = bl[i] = 0, g[i].clear();
        for (int i = 1, u, v; i <= m; ++i) {
            read (u), read (v), add (u, v), add (v, u);
            // if (TT == 8) printf ("%d %d\n", u, v);
        }
        for (int i = 1; i <= n; ++i) fa[i] = i;
        for (int i = 1; i <= n; ++i)
            if (c[i] != n - 1 && !num[i]) {
                for (int j = 1; j <= n; ++j)
                    if (i != j && e[i].find (j) == e[i].end ())
                        { link (i, j), link (j, i); break; }
            }   // 连边弄成一个森林
        // for (int i = 1; i <= n; ++i) {
        //     for (int j : g[i]) printf ("%d ", j); puts ("");
        // }
        for (int i = 1; i <= n; ++i) {
            if (c[i] == n - 1) a[i] = b[i] = now++;
            else if (!bl[i]) p = tp = 0, dfs (i, i), work ();
        }    // 开始华丽的构造star
        for (int i = 1; i <= n; ++i) printf ("%d ", a[i]); puts ("");
        for (int i = 1; i <= n; ++i) printf ("%d ", b[i]); puts ("");
    }
}
