This is the easy version of the problem. The only difference between the easy and hard versions is that, in the easy one, additionally, there exists a solution with at least 2 employees in every department.

ChefCorp has N employees. Each employee belongs to exactly one of the M departments. Each department is headed by exactly one of the employees belonging to that department.

The management structure of ChefCorp is as follows:
Each employee of a department (including its head) is *in contact* with every other employee of that department.
The head of each department is *in contact* with the heads of all the other departments.

For example, let N = 7, M = 3 and employees 1, \textbf{2}, 3 belong to the first department, employees \textbf{4}, 5 belong to the second department and employees \textbf{6}, 7 belong to the third department (employees in bold represent the heads of the departments). The following pairs of employees are in contact with each other: (1, 2), (1, 3), (2, 3), (4, 5), (6, 7), (2, 4), (4, 6), (2, 6).

However, due to some inexplicable reasons, ChefCorp loses all its data on the departments. Given the total number of employees N and every pair of employees who are *in contact* with each other, can you help recover the number of departments and the employees belonging to each of the departments?

------ Input Format ------ 

- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer N — the total number of employees in ChefCorp.
- The second line of each test case contains a single integer K — the number of pairs of employees *in contact* with each other.
- K lines follow. The i^{th} of these K lines contain two space-separated integers u_{i} and v_{i}, denoting that employee u_{i} is *in contact* with v_{i}.

------ Output Format ------ 

- For each test case, output the following:
- In the first line output M — the number of departments.
- In the second line, output N space-separated integers D_{1}, D_{2}, \ldots, D_{N} (1 ≤ D_{i} ≤ M) — denoting that the i^{th} employee belongs to the D_{i}^{th} department.
- In the third line, output M space-separated integers H_{1}, H_{2}, \ldots, H_{M} (1 ≤ H_{i} ≤ N, H_{i} \neq H_{j} when i \neq j) — denoting that the H_{i}^{th} employee is the head of the i^{th} department.

If there are multiple answers, output any. It is guaranteed that at least one solution always exists.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 1000$
$1 ≤ K ≤ \frac{N\cdot(N-1)}{2}$
$1 ≤ u_{i}, v_{i} ≤ N$
$u_{i} \neq v_{i}$ for each $1 ≤ i ≤ K$.
- It is guaranteed that there exists a solution in which there are at least two employees in every department.
- The sum of $N$ over all test cases does not exceed $3000$.

----- Sample Input 1 ------ 
3
7
8
1 2
1 3
2 3
4 5
6 7
2 4
4 6
2 6
2
1
1 2
6
8
6 2
5 4
3 1
5 2
3 6
2 1
6 1
2 3

----- Sample Output 1 ------ 
3
1 1 1 2 2 3 3
2 4 6
1
1 1
1
2
1 1 1 2 2 1
2 5

----- explanation 1 ------ 
Test Case $1$: Explained in the problem statement.

Difficulty: VERY_HARD

Solutions:
t = int(input())

def Intersection(lst1, lst2):
	return set(lst1).intersection(lst2)
for _ in range(t):
	n = int(input())
	pair = int(input())
	d = {}
	for value in range(pair):
		(a, b) = map(int, input().split())
		if a in d:
			d[a].append(b)
		else:
			d[a] = [b]
		if b in d:
			d[b].append(a)
		else:
			d[b] = [a]
	d = dict(sorted(d.items(), key=lambda item: len(item[1])))
	if n == 2:
		print(1)
		print(1, 1)
		print(1)
		continue
	for (key, value) in d.items():
		smallestKey = key
		break
	values = []
	values = d[smallestKey]
	totalValues = values.copy()
	totalValues.append(smallestKey)
	manager = []
	managerDict = {}
	for i in values:
		for j in d[i]:
			if j in totalValues:
				continue
			else:
				manager.append(j)
				manager.append(i)
	for (key, value) in d.items():
		if manager in value:
			manager.append(key)
	managerSet = set(manager.copy())
	manager = list(managerSet)
	for i in range(len(manager)):
		managerDict[manager[i]] = i + 1
	print(len(managerSet))
	ans = []
	for i in range(n):
		if i + 1 in manager:
			ans.append(managerDict[i + 1])
			continue
		common = Intersection(d[i + 1], manager).pop()
		ans.append(managerDict[common])
	print(*ans)
	print(*managerSet)


from collections import *
for _ in range(int(input())):
	n = int(input())
	d = [0] * (n + 1)
	arr = []
	q = int(input())
	gr = [[] for i in range(n + 1)]
	for i in range(q):
		arr.append(list(map(int, input().split())))
		d[arr[i][0]] += 1
		d[arr[i][1]] += 1
		gr[arr[i][0]].append(arr[i][1])
		gr[arr[i][1]].append(arr[i][0])
	new = []
	for i in range(1, n + 1):
		new.append([i, d[i]])
	new.sort(key=lambda x: x[-1], reverse=True)
	root = new[0][0]
	d = deque()
	d.append(root)
	par = [-1] * (n + 1)
	par[root] = root
	v = set()
	v.add(root)
	while d:
		x = d.popleft()
		for i in gr[x]:
			if i not in v:
				par[i] = x
				v.add(i)
				d.append(i)
	s = set()
	for i in range(1, n + 1):
		s.add(par[i])
	if -1 in s:
		s.remove(-1)
	print(len(s))
	he = sorted(list(s))
	d = defaultdict(lambda : 0)
	for i in range(len(he)):
		d[he[i]] = i + 1
		par[he[i]] = he[i]
	ans = [0] * (n + 1)
	for i in range(1, n + 1):
		ans[i] = d[par[i]]
	print(*ans[1:])
	print(*he)


from collections import defaultdict
from collections import defaultdict, deque, Counter
from itertools import groupby, accumulate, cycle, chain
from bisect import bisect_left, bisect_right
from math import inf
from string import ascii_lowercase, ascii_uppercase
from copy import deepcopy
from heapq import heapify, heappush, heappop
from functools import lru_cache
import re
T = int(input())
vt = lambda t: [t(num) for num in input().split()]
it = lambda : vt(int)[0]
st = lambda a: a.sort()

def run_tc():
	n = it()
	e = it()
	ind = defaultdict(int)
	adj = defaultdict(list)
	for _ in range(e):
		(u, v) = vt(int)
		ind[u] += 1
		ind[v] += 1
		adj[u].append(v)
		adj[v].append(u)
	S = sorted(ind.items(), key=lambda x: x[1])
	u = S[0][0]
	m = None
	for v in adj[u]:
		if ind[v] > ind[u]:
			m = v
			break
	if m is not None:
		mgr = [x for x in adj[m] if ind[x] != ind[u]]
		mgr += [m]
		mgr.sort()
		ans = [0] * n
		D = 1
		seen = set(mgr)
		for y in mgr:
			ans[y - 1] = D
			for v in adj[y]:
				if v not in seen:
					ans[v - 1] = D
					seen.add(v)
			D += 1
		print(len(mgr))
		print(*ans)
		print(*mgr)
	else:
		print(1)
		print(*[1] * n)
		print(1)
for _ in range(T):
	run_tc()


import math
from bisect import bisect, bisect_left, bisect_right
import heapq
from math import gcd, floor, sqrt, log
from collections import defaultdict as ddc
from collections import Counter

def intin():
	return int(input())

def mapin():
	return map(int, input().split())

def strin():
	return input().split()
INF = 10 ** 20
mod = 1000000007

def LIS(arr, n):
	dp = [10 ** 9] * (n + 1)
	for ele in arr:
		dp[bisect_left(dp, ele)] = ele
	return bisect_left(dp, 10 ** 9)

def exponentiation(bas, exp, mod=1000000007):
	t = 1
	while exp > 0:
		if exp % 2 != 0:
			t = t * bas % mod
		bas = bas * bas % mod
		exp //= 2
	return t % mod

def MOD(p, q=1, mod=1000000007):
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p
yes = 'YES'
no = 'NO'
even = 'EVEN'
odd = 'ODD'

def process(graph, n, k):
	ans = [0] * n
	m = 1
	heads = set()
	head = ddc(int)
	for i in range(n):
		for v in graph[i]:
			if len(graph[i]) > len(graph[v]):
				heads.add(i)
				head[m] = i + 1
				ans[i] = m
				m += 1
				break
	if not heads:
		for i in range(n):
			ans[i] = m
		head[m] = 1
		m += 1
	else:
		for w in heads:
			for ww in heads:
				if w != ww:
					graph[w].discard(ww)
			for v in graph[w]:
				ans[v] = ans[w]
	print(m - 1)
	print(*ans)
	print(*[head[i] for i in range(1, m)])

def main():
	for _ in range(int(input())):
		n = intin()
		k = intin()
		graph = ddc(set)
		for i in range(k):
			(u, v) = mapin()
			graph[u - 1].add(v - 1)
			graph[v - 1].add(u - 1)
		process(graph, n, k)
main()


T = int(input())
for i in range(T):
	N = int(input())
	K = int(input())
	rel = {}
	deg = {}
	for j in range(K):
		(a, b) = list(map(int, input().strip().split(' ')))
		if a in rel:
			rel[a].append(b)
			deg[a] += 1
		else:
			rel[a] = [b]
			deg[a] = 1
		if b in rel:
			rel[b].append(a)
			deg[b] += 1
		else:
			rel[b] = [a]
			deg[b] = 1
	if K == N * (N - 1) // 2:
		print(1)
		print(('1 ' * N).strip())
		print(1)
	else:
		min_deg = N + 1
		min_deg_person = None
		for person in deg:
			if deg[person] < min_deg:
				min_deg = deg[person]
				min_deg_person = person
		M = []
		for frnd in rel[min_deg_person]:
			if deg[frnd] != deg[min_deg_person]:
				manager = frnd
				manager_grp = set(rel[frnd])
				manager_grp.add(frnd)
				employee_grp = set(rel[min_deg_person])
				employee_grp.add(min_deg_person)
				employee_grp.remove(frnd)
				M = list(manager_grp - employee_grp)
				break
		M.sort()
		ans = []
		for i in range(1, N + 1):
			if i in M:
				ans.append(M.index(i) + 1)
			else:
				man = list(set(M).intersection(set(rel[i])))
				ans.append(M.index(man[0]) + 1)
		print(len(M))
		gr = [str(w) for w in ans]
		gr = ' '.join(gr)
		ma = [str(w) for w in M]
		ma = ' '.join(ma)
		print(gr)
		print(ma)


from functools import cmp_to_key
from collections import Counter, deque, defaultdict, OrderedDict
import math
from bisect import bisect, bisect_left
import sys
import re
MOD = 10 ** 9 + 7
MAX = -sys.maxsize
MIN = sys.maxsize

class get:

	def int():
		return list(map(int, input().split()))

	def str():
		return input().split()

	def float():
		return list(map(float, input().split()))

	def map():
		return map(int, input().split())

def sqrt(x):
	return int(math.sqrt(x)) + 1

def gcd(*args):
	result = args[0]
	for item in args:
		result = math.gcd(result, item)
	return result

def LCM(a, b):
	return a * b // math.gcd(a, b)

def isPrime(n):
	if n == 1:
		return False
	for i in range(2, sqrt(n)):
		if n % i == 0:
			return False
	return True

def solve():
	n = int(input())
	k = int(input())
	edge = defaultdict(set)
	(m, max_) = (0, 0)
	for _ in range(k):
		(a, b) = get.map()
		edge[a].add(b)
		edge[b].add(a)
		if len(edge[a]) > max_:
			max_ = len(edge[a])
			m = a
		if len(edge[b]) > max_:
			max_ = len(edge[b])
			m = b
	if k == n * (n - 1) // 2:
		print(1)
		print(*[1 for i in range(n)])
		print(1)
		return
	dep = {m: [1, [m]]}
	visited = set()
	visited.add(m)
	heads = deque([m])
	j = 1
	while len(heads) > 0:
		curr_head = heads.popleft()
		curr_dep = dep[curr_head][0]
		child_of_head = edge[curr_head]
		for item in child_of_head:
			if item not in visited:
				visited.add(item)
				child_of_item = edge[item]
				ss = child_of_item.intersection(child_of_head)
				ss.add(curr_head)
				if child_of_item == ss:
					dep[curr_head][1].append(item)
				else:
					dep[item] = [j + 1, [item]]
					j += 1
					heads.append(item)
	print(len(dep))
	emp = [0] * n
	heads = []
	for (a, b) in dep.items():
		heads.append(a)
		for item in b[1]:
			emp[item - 1] = b[0]
	print(*emp)
	print(*heads)
t = int(input())
for tt in range(t):
	solve()


import time
import sys
import math
(mod, infi) = (1000000007, sys.maxsize)
from collections import deque, Counter, defaultdict as dd
from itertools import accumulate
from functools import lru_cache, reduce
from operator import mul, add, sub, truediv, floordiv, lt, le, eq, ne, gt, xor, concat, getitem, pow, lshift
inty = lambda : int(input())
stringy = lambda : input().strip()
mappy = lambda : map(int, input().strip().split())
fmappy = lambda : map(float, input().strip().split())
listy = lambda : list(map(int, input().strip().split()))
sys.setrecursionlimit(10 ** 6)
tick = lambda : time.perf_counter()
logg = lambda a, b: math.log2(a) / math.log2(b)
acc = lambda x: list(accumulate(x))
sign = lambda x, y: x >= 0 and y >= 0 or (x < 0 and y < 0)
T = inty()
for _ in range(T):
	n = inty()
	k = inty()
	graph = dd(set)
	for _ in range(k):
		(u, v) = mappy()
		graph[u].add(v)
		graph[v].add(u)
	mini = infi
	start = 0
	for node in graph:
		if len(graph[node]) < mini:
			mini = len(graph[node])
			start = node
	head = set()
	for node in graph[start]:
		if len(graph[node]) > mini:
			head |= graph[node] - graph[start]
			head |= {node}
			head -= {start}
	if not head:
		head |= {1}
	z = [0] * n
	r = 1
	for node in head:
		for nnode in graph[node]:
			if nnode not in head:
				z[nnode - 1] = r
		z[node - 1] = r
		r += 1
	print(len(head))
	print(*z)
	print(*head)


for _ in range(int(input())):
	n = int(input())
	k = int(input())
	head = [[] for i in range(n + 1)]
	child = []
	nor = [{i} for i in range(n + 1)]
	final = [0] * (n + 1)
	fnlhead = []
	if n == 2:
		(a, b) = map(int, input().split())
		print(1)
		print(*[1, 1])
		print(a)
	else:
		for i in range(k):
			(a, b) = map(int, input().split())
			nor[a].add(b)
			nor[b].add(a)
		for i in range(1, n + 1):
			for j in nor[i]:
				if nor[i] < nor[j]:
					head[j].append(i)
		grp = 1
		for i in range(n + 1):
			if len(head[i]) != 0:
				final[i] = grp
				fnlhead.append(i)
				for j in head[i]:
					final[j] = grp
				grp += 1
		print(len(fnlhead))
		print(*final[1:])
		print(*fnlhead)


m = int(input())
for i in range(m):
	n = int(input())
	k = int(input())
	d = {}
	l = [0 for j in range(n)]
	h = []
	if n == 2:
		l = [1, 1]
		h = [1]
	for j in range(k):
		z = input().split()
		if int(z[0]) in d:
			d[int(z[0])] += [int(z[1])]
		else:
			d[int(z[0])] = [int(z[1])]
		if int(z[1]) in d:
			d[int(z[1])] += [int(z[0])]
		else:
			d[int(z[1])] = [int(z[0])]
	b = 1
	for j in range(1, n + 1):
		if l[j - 1] == 0:
			t = d[j]
			p = 0
			for k in range(len(t)):
				if len(d[t[k]]) < len(t):
					p = 1
					y = t[k]
			if p != 1:
				l[j - 1] = b
				for k in range(len(t)):
					if len(d[t[k]]) > len(t):
						l[t[k] - 1] = b
						h += [t[k]]
					else:
						l[t[k] - 1] = b
				b += 1
	print(len(h))
	print(' '.join(map(str, l)))
	print(' '.join(map(str, h)))


n = int(input())
for i in range(n):
	e = int(input())
	c = int(input())
	d = {}
	for j in range(1, e + 1):
		d[j] = []
		d[j].append(j)
	for j in range(c):
		(x, y) = map(int, input().split())
		d[x].append(y)
		d[y].append(x)
	m = 1
	for j in range(1, e + 1):
		d[j].sort()
		if len(d[m]) < len(d[j]):
			m = j
	h = []
	h.append(m)
	for j in d[m]:
		f = 0
		for k in d[j]:
			if k in d[m]:
				pass
			else:
				f = 1
		if f == 1:
			h.append(j)
	print(len(h))
	l = []
	for j in range(1, e + 1):
		f = 0
		for k in range(len(h)):
			if j in d[h[k]] and j not in h:
				l.append(k + 1)
				break
		if j in h:
			l.append(h.index(j) + 1)
	print(*l)
	print(*h)


for _ in range(int(input())):
	n = int(input())
	k = int(input())
	a = [[x] for x in range(n)]
	for i in range(k):
		(temp1, temp2) = map(int, input().split())
		a[temp1 - 1].append(temp2 - 1)
		a[temp2 - 1].append(temp1 - 1)
	big = -1
	pos = -1
	for i in range(n):
		if len(a[i]) > big:
			pos = i
			big = len(a[i])
	head = []
	for i in a[pos]:
		if set(a[i]).issubset(set(a[pos])):
			pass
		else:
			head.append(i)
	head.insert(0, pos)
	departs = [0 for x in range(len(head))]
	for i in range(len(departs)):
		departs[i] = list(set(a[head[i]]) - set(head))
		departs[i].append(head[i])
	emp_depart = [0 for x in range(n)]
	for i in range(len(head)):
		for j in departs[i]:
			emp_depart[j] = i + 1
		emp_depart[head[i]] = i + 1
	print(len(departs))
	print(*emp_depart)
	print(*[x + 1 for x in head])


from collections import *

def findNew(new, d):
	for i in range(1, n + 1):
		new.append([i, d[i]])
	new.sort(key=lambda x: x[-1], reverse=True)
	return new

def bfs(new, graph):
	root = new[0][0]
	d = deque()
	d.append(root)
	par = [-1] * (n + 1)
	par[root] = root
	v = set()
	v.add(root)
	while d:
		x = d.popleft()
		for i in graph[x]:
			if i not in v:
				par[i] = x
				v.add(i)
				d.append(i)
	s = set()
	for i in range(1, n + 1):
		s.add(par[i])
	if -1 in s:
		s.remove(-1)
	print(len(s))
	he = sorted(list(s))
	d = defaultdict(lambda : 0)
	for i in range(len(he)):
		d[he[i]] = i + 1
		par[he[i]] = he[i]
	return (d, par, he)
for _ in range(int(input())):
	n = int(input())
	d = [0] * (n + 1)
	arr = []
	q = int(input())
	graph = [[] for i in range(n + 1)]

	def makegraph():
		for i in range(q):
			arr.append(list(map(int, input().split())))
			d[arr[i][0]] += 1
			d[arr[i][1]] += 1
			graph[arr[i][0]].append(arr[i][1])
			graph[arr[i][1]].append(arr[i][0])
	makegraph()
	neww = findNew([], d)
	(d, par, he) = bfs(neww, graph)
	ans = [0] * (n + 1)
	for i in range(1, n + 1):
		ans[i] = d[par[i]]
	print(*ans[1:])
	print(*he)


for tc in range(int(input())):
	m = int(input())
	k = int(input())
	d = dict.fromkeys(range(1, m + 1), None)
	a = dict.fromkeys(range(1, m + 1), None)
	for i in range(1, k + 1):
		(p1, p2) = map(int, input().split())
		if d[p1] is None:
			d[p1] = set()
		if d[p2] is None:
			d[p2] = set()
		d[p1].add(p2)
		d[p2].add(p1)
	h = list()
	c = 1
	for i in range(1, m + 1):
		if a[i] is not None:
			continue
		p1 = d[i]
		not_lead = False
		if len(p1) == 1:
			not_lead = True
		else:
			for j in p1:
				p2 = d[j]
				if len(p1 ^ p2) == 2:
					not_lead = True
		if not_lead:
			a[i] = c
			for j in p1:
				a[j] = c
				if len(d[j]) > len(p1):
					h.append(j)
			if len(h) < c:
				h.append(i)
			c += 1
	print(c - 1)
	print(' '.join((str(x) for x in a.values())))
	print(' '.join((str(x) for x in h)))


from collections import defaultdict
import math
import sys
mod = 10 ** 9 + 7

def facto(n):
	ans = 1
	while n:
		ans = ans * 2 % mod
	return ans

class Solve:

	def __init__(self, n, k):
		self.n = n
		self.k = k
		self.st = set()

	def dp(self, ones, zeroes):
		if ones < 0 or zeroes < 0:
			return
		if ones in self.st:
			return
		self.st.add(ones)
		for i in range(zeroes + 1):
			if ones >= self.k - i:
				self.dp(ones + i - (self.k - i), zeroes - i + (self.k - i))
		for i in range(ones + 1):
			if zeroes >= self.k - i:
				self.dp(ones - i + (self.k - i), zeroes + i - (self.k - i))

def solve():
	n = int(input())
	k = int(input())
	hs = defaultdict(lambda : set())
	queries = []
	for _ in range(k):
		(alpha, beta) = map(int, input().split())
		queries.append((alpha, beta))
		hs[alpha].add(beta)
		hs[beta].add(alpha)
	groups = []
	managers = set()
	ans = defaultdict(int)
	unique = 0
	for q in queries:
		(a, b) = q
		if len(hs[a]) > len(hs[b]):
			if len(hs[b].difference(hs[a].union({a}))) == 0:
				managers.add(a)
		elif len(hs[b]) > len(hs[a]):
			if len(hs[a].difference(hs[b].union({b}))) == 0:
				managers.add(b)
		else:
			pass
	ans = defaultdict(int)
	ansb = []
	for (i, x) in enumerate(managers):
		ansb.append(x)
		ans[x] = i + 1
		for y in hs[x]:
			if y not in managers:
				ans[y] = i + 1
	if len(ansb) == 0:
		print(1)
		print(' '.join(['1' for x in range(n)]))
		print(1)
	else:
		print(len(ansb))
		print(' '.join([str(ans[x + 1]) for x in range(n)]))
		print(' '.join([str(x) for x in ansb]))
for _ in range(int(input())):
	solve()


mod = 10 ** 9 + 7
t = int(input())
for t0 in range(t):
	n = int(input())
	k = int(input())
	pairs = []
	adjacent = {}
	for i in range(k):
		pair = list(map(int, input().split()))
		if not adjacent.__contains__(pair[0]):
			adjacent[pair[0]] = set()
		if not adjacent.__contains__(pair[1]):
			adjacent[pair[1]] = set()
		adjacent[pair[0]].add(pair[1])
		adjacent[pair[1]].add(pair[0])
		pairs.append(pair)
	heads = set()
	for pair in pairs:
		if len(adjacent[pair[0]]) > len(adjacent[pair[1]]):
			heads.add(pair[0])
		if len(adjacent[pair[1]]) > len(adjacent[pair[0]]):
			heads.add(pair[1])
	if len(heads) == 0:
		print(1)
		print(' '.join([str(item) for item in [1] * n]))
		print(1)
		continue
	if len(heads) == 1:
		a = set()
		b = set()
		good_head = list(heads)[0]
		reminded_nodes = list(adjacent[good_head])
		a_cap = reminded_nodes[0]
		a.add(a_cap)
		for i in range(1, len(reminded_nodes)):
			node = reminded_nodes[i]
			if adjacent[node].__contains__(a_cap):
				a.add(node)
			else:
				b.add(node)
		dep_num = {good_head: 1}
		counter = 2
		for head in a:
			dep_num[head] = counter
			counter += 1
		for node in b:
			dep_num[node] = 1
		print(2)
		print(' '.join([str(dep_num[node]) for node in range(1, n + 1)]))
		all_heads = list(a)
		all_heads.append(good_head)
		print(' '.join([str(head) for head in all_heads]))
		continue
	head_of_node = {}
	for node in range(1, n + 1):
		if heads.__contains__(node):
			continue
		for adj in adjacent[node]:
			if heads.__contains__(adj):
				if head_of_node.__contains__(node):
					del head_of_node[node]
					heads.add(node)
					break
				else:
					head_of_node[node] = adj
	dep_num = {}
	counter = 1
	for head in heads:
		dep_num[head] = counter
		counter += 1
	print(len(heads))
	line2 = []
	for node in range(1, n + 1):
		if heads.__contains__(node):
			head = node
		else:
			head = head_of_node[node]
		line2.append(str(dep_num[head]))
	print(' '.join(line2))
	print(' '.join([str(head) for head in heads]))


from collections import *
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	q = defaultdict(set)
	for i in range(k):
		(x, y) = map(int, input().split())
		q[x].add(y)
		q[y].add(x)
	o = 100000
	x = 1
	for i in q:
		if len(q[i]) < o:
			o = len(q[i])
			x = i
	head = set()
	for j in q[x]:
		if len(q[j]) > o:
			head |= q[j] - q[x]
			head |= {j}
			head -= {x}
			break
	if not head:
		head |= {1}
	z = [0] * n
	r = 1
	for i in head:
		for j in q[i]:
			if j not in head:
				z[j - 1] = r
		z[i - 1] = r
		r += 1
	print(len(head))
	print(*z)
	print(*head)


tc = int(input())
for _ in range(tc):
	n = int(input())
	k = int(input())
	adjl = [set() for _ in range(n)]
	for i in range(k):
		(u, v) = map(int, input().split())
		adjl[u - 1].add(v - 1)
		adjl[v - 1].add(u - 1)
	maxd = 0
	md = -1
	for i in range(n):
		if len(adjl[i]) > maxd:
			maxd = len(adjl[i])
			md = i
	p = set(adjl[md])
	start = p.pop()
	p = set(adjl[start])
	p.remove(md)
	p.add(start)
	if len(p.difference(adjl[md])) == 0:
		managers = adjl[md].difference(p)
	else:
		managers = adjl[md].intersection(p)
	managers.add(md)
	m = len(managers)
	print(m)
	d = [0 for i in range(n)]
	k = 1
	manx = list(managers)
	for tm in manx:
		d[tm] = k
		for v in adjl[tm]:
			if not v in managers:
				d[v] = k
		k += 1
	print(*d)
	print(*[t + 1 for t in manx])