#include <iostream>
#include <cstdio>
#include <cctype>
#include <set>
using namespace std;
const int MAXN=5e5+5;
int vis[MAXN],a[MAXN],b[MAXN];
set<int> edge[MAXN],s[MAXN];
inline int read()
{
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x;
}
inline void solve()
{
	int n=read(),m=read();
	for(int i=1;i<=n;i++)
		s[i].clear(),
		edge[i].clear(),
		vis[i]=a[i]=b[i]=0;
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		edge[x].insert(y);
		edge[y].insert(x);
	}
	for(int i=1;i<=n;i++)
	{
		int p=1;
		edge[i].insert(i);
		if(vis[i]) continue;
		if(edge[i].size()==n) continue;
		for(auto x:edge[i]) if(x^p) break; else p++;
		if(!vis[p]) vis[p]=vis[i]=i,s[i].insert(p);
		else if(vis[p]==p) vis[i]=p,s[p].insert(i);
		else if(s[vis[p]].size()==1)
			s[vis[p]].erase(p),s[p].insert(vis[p]),
			s[p].insert(i),vis[vis[p]]=p,vis[p]=vis[i]=p;
		else s[vis[p]].erase(p),vis[p]=vis[i]=i,s[i].insert(p);
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(vis[i]==i)
		{
			a[i]=++cnt;
			for(auto x:s[i])
				b[x]=cnt,a[x]=++cnt;
			b[i]=cnt;
		}
	for(int i=1;i<=n;i++)
		if(!a[i]&&!b[i])
			a[i]=b[i]=++cnt;
	for(int i=1;i<=n;i++)
		printf("%d%c",a[i]," \n"[i==n]);
	for(int i=1;i<=n;i++)
		printf("%d%c",b[i]," \n"[i==n]);
}
int main()
{
	int t=read();
	while(t--) solve();
	return 0;
}