#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;

cs int N = 5e5 + 50; 
int T, n, m, p[N], q[N], fa[N];
vector<int> G[N], e[N];
int fnd(int x){ return x == fa[x] ? x : fa[x] = fnd(fa[x]); }
bool ex[N]; vector<int> S[N];
bool dfs(int u, int f){
	ex[u] = true; 
	for(int o = 0, v; o < e[u].size(); o++)
	if((v = e[u][o]) != f){
		if(dfs(v, u)) S[u].pb(v); 	
	} if(S[u].empty() && !f) 
	S[e[u][0]].pb(u);
	return S[u].empty();
}
void Main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		G[i].clear(), e[i].clear(), S[i].clear();
	for(int i = 1; i <= n; i++) fa[i] = i, ex[i] = 0; 
	for(int i = 1, u, v; i <= m; i++)
		scanf("%d%d", &u, &v), 
		G[u].pb(v), G[v].pb(u);
	int ind = 0; 
	for(int i = 1; i <= n; i++){
		sort(G[i].begin(), G[i].end());
		int t = 1 + (i == 1), k = 0;
		while(true){
			if(k == G[i].size() || G[i][k] != t) break;
			++k, ++t; if(t == i) ++t; 
		} if(t > n) p[i] = q[i] = ++ind;
		else if(fnd(t) != fnd(i))
		fa[fnd(i)] = fnd(t), e[i].pb(t), e[t].pb(i);
	}
	for(int i = 1; i <= n; i++)
		if(!ex[i] && e[i].size()) dfs(i, 0);
	for(int i = 1; i <= n; i++)
	if(S[i].size()){
		p[i] = ++ind;
		for(int o = 0, v; o < S[i].size(); o++){
			v = S[i][o];
			q[v] = ind, p[v] = ++ind;
		} q[i] = ind;
	}
	for(int i = 1; i <= n; i++)
		cout << p[i] << " "; puts("");
	for(int i = 1; i <= n; i++)
		cout << q[i] << " "; puts("");
}
int main(){
	#ifdef FSYo
	freopen("1.in", "r", stdin);
	#endif
	cin >> T; 
	while(T--) Main();
	return 0;
}