Ivan is a novice painter. He has $n$ dyes of different colors. He also knows exactly $m$ pairs of colors which harmonize with each other.

Ivan also enjoy playing chess. He has $5000$ rooks. He wants to take $k$ rooks, paint each of them in one of $n$ colors and then place this $k$ rooks on a chessboard of size $10^{9} \times 10^{9}$.

Let's call the set of rooks on the board connected if from any rook we can get to any other rook in this set moving only through cells with rooks from this set. Assume that rooks can jump over other rooks, in other words a rook can go to any cell which shares vertical and to any cell which shares horizontal.

Ivan wants his arrangement of rooks to have following properties: For any color there is a rook of this color on a board; For any color the set of rooks of this color is connected; For any two different colors $a$ $b$ union of set of rooks of color $a$ and set of rooks of color $b$ is connected if and only if this two colors harmonize with each other.

Please help Ivan find such an arrangement.


-----Input-----

The first line of input contains $2$ integers $n$, $m$ ($1 \le n \le 100$, $0 \le m \le min(1000, \,\, \frac{n(n-1)}{2})$) — number of colors and number of pairs of colors which harmonize with each other.

In next $m$ lines pairs of colors which harmonize with each other are listed. Colors are numbered from $1$ to $n$. It is guaranteed that no pair occurs twice in this list.


-----Output-----

Print $n$ blocks, $i$-th of them describes rooks of $i$-th color.

In the first line of block print one number $a_{i}$ ($1 \le a_{i} \le 5000$) — number of rooks of color $i$. In each of next $a_{i}$ lines print two integers $x$ and $y$ ($1 \le x, \,\, y \le 10^{9}$) — coordinates of the next rook.

All rooks must be on different cells.

Total number of rooks must not exceed $5000$.

It is guaranteed that the solution exists.


-----Examples-----
Input
3 2
1 2
2 3

Output
2
3 4
1 4
4
1 2
2 2
2 4
5 4
1
5 1

Input
3 3
1 2
2 3
3 1

Output
1
1 1
1
1 2
1
1 3

Input
3 1
1 3

Output
1
1 1
1
2 2
1
3 1



-----Note-----

Rooks arrangements for all three examples (red is color $1$, green is color $2$ and blue is color $3$).

$\left. \begin{array}{|l|l|l|l|l|l|l|} \hline 5 & {} & {} & {} & {} & {} \\ \hline 4 & {} & {} & {} & {} & {} \\ \hline 3 & {} & {} & {} & {} & {} \\ \hline 2 & {} & {} & {} & {} & {} \\ \hline 1 & {} & {} & {} & {} & {} \\ \hline & {1} & {2} & {3} & {4} & {5} \\ \hline \end{array} \right.$

$\left. \begin{array}{|l|l|l|l|} \hline 2 & {} & {} & {} \\ \hline 1 & {} & {} & {} \\ \hline & {1} & {2} & {3} \\ \hline \end{array} \right.$

$\left. \begin{array}{|l|l|l|l|} \hline 2 & {} & {} & {} \\ \hline 1 & {} & {} & {} \\ \hline & {1} & {2} & {3} \\ \hline \end{array} \right.$

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Constructive algorithms


Solutions:
(cols, pairs) = [int(x) for x in input().split()]
import collections
d = collections.defaultdict(list)
for _ in range(pairs):
	(a, b) = [int(x) for x in input().split()]
	d[a].append(b)
rooks = collections.defaultdict(list)
current_line = 1
for i in range(1, cols + 1):
	rooks[i].append((i, current_line))
	current_line += 1
	for harmony in d[i]:
		rooks[i].append((i, current_line))
		rooks[harmony].append((harmony, current_line))
		current_line += 1
for i in range(1, cols + 1):
	print(len(rooks[i]))
	for (a, b) in rooks[i]:
		print(a, b)


from typing import Dict, List
(n_colors, len_pairs) = (int(val) for val in input().split())
color_pairs = []
for i in range(len_pairs):
	color_pairs.append([int(val) for val in input().split()])
res = []
cur_x = 1
cur_y = 1
for color in range(1, n_colors + 1):
	cur_color_res = []
	cur_color_res.append((cur_x, cur_y))
	cur_x += 1
	cur_y += 1
	res.append(cur_color_res)
for pair in color_pairs:
	res[pair[0] - 1].append((cur_x, cur_y))
	res[pair[0] - 1].append((cur_x, pair[0]))
	res[pair[1] - 1].append((cur_x, pair[1]))
	cur_x += 1
	cur_y += 1
for cur_res in res:
	print(len(cur_res))
	for el_cur_res in cur_res:
		print('{} {}'.format(el_cur_res[0], el_cur_res[1]))


(n, m) = [int(x) for x in input().split()]
ms = []
con = [set() for i in range(n)]
loc = [0] * n
for i in range(m):
	(a, b) = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	con[a].add(b)
	con[b].add(a)
	ms.append((a, b))
ans = [[] for i in range(n)]
if len(con[0]) == 0:
	con[0].add(n + 10)
l = len(con[0])
ans[0] = [i for i in range(l)]
for i in range(1, n):
	loc[i] = l
	if len(con[i]) == 0:
		con[i].add(n + 10)
	for s in con[i]:
		if s < i:
			ans[i].append(loc[s])
			loc[s] += 1
		else:
			ans[i].append(l)
			l += 1
for i in range(n):
	print(len(ans[i]))
	for s in ans[i]:
		print(i + 1, s + 1)


def main():
	(n, m) = map(int, input().split())
	arr = [[] for i in range(n + 1)]
	answ = [[] for i in range(n + 1)]
	x = 1
	for i in range(m):
		(a, b) = map(int, input().split())
		arr[a].append([a, x])
		arr[b].append([b, x])
		x += 1
	for i in range(1, n + 1):
		if not arr[i]:
			print(1)
			print(i, x)
			x += 1
		else:
			print(len(arr[i]))
			for j in arr[i]:
				print(*j)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
(n, m) = RL()
dic = [[i] for i in range(n + 1)]
count = [1] * (n + 1)
for _ in range(m):
	(a, b) = RL()
	if a != b:
		dic[a].append(b)
		dic[b].append(a)
for i in range(1, n + 1):
	print(len(dic[i]) + 1)
	print(i, i)
	for j in dic[i]:
		print(i, min(i, j) * n + max(i, j))


3
import math
import sys
DEBUG = False

def inp():
	return sys.stdin.readline().rstrip()

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def solve(N, M, A):
	ans = [[] for _ in range(N)]
	for i in range(1, N + 1):
		ans[i - 1].append((i, i))
	y = N + 1
	for a in range(1, N + 1):
		for b in range(a + 1, N + 1):
			if A[a][b] == 1:
				ans[a - 1].append((a, y))
				ans[b - 1].append((b, y))
				y += 1
	return ans

def main():
	(N, M) = [int(e) for e in inp().split()]
	A = [bytearray(N + 1) for _ in range(N + 1)]
	for _ in range(M):
		(a, b) = [int(e) for e in inp().split()]
		A[a][b] = 1
		A[b][a] = 1
	ans = solve(N, M, A)
	assert len(ans) == N
	for coords in ans:
		print(len(coords))
		for (x, y) in coords:
			print(x, y)

def __starting_point():
	main()
__starting_point()


(n, m) = [int(el) for el in input().split()]
pair = []
kol = {i: 1 for i in range(1, n + 1)}
for i in range(m):
	(q, w) = [int(el) for el in input().split()]
	if q < w:
		pair.append((q, w))
	else:
		(q, w) = (w, q)
		pair.append((q, w))
	kol[q] += 1
	kol[w] += 1
pair.sort()
mazy = []
for i in range(1, n + 1):
	mazy.append((i, i, i))
for i in pair:
	mazy.append((i[0], 10000 * i[1] + i[0], i[0]))
	mazy.append((i[1], 10000 * i[1] + i[0], i[1]))
mazy.sort()
cur = 1
print(kol[1])
while mazy != []:
	q = mazy.pop(0)
	if q[0] == cur:
		print(q[1], q[0])
	else:
		print(kol[q[0]])
		print(q[1], q[0])
		cur = q[0]


from collections import defaultdict
(n, m) = list(map(int, input().split()))
pairs = defaultdict(set)
for _ in range(m):
	(l, r) = list(map(int, input().split()))
	pairs[l - 1].add(r - 1)
	pairs[r - 1].add(l - 1)
answers = defaultdict(list)
free_rooks = defaultdict(int)
y = 1
for color in range(n):
	free_rooks[color] = y
	for c in pairs[color]:
		if c < color:
			answers[color].append((color + 1, free_rooks[c]))
			free_rooks[c] += 1
		else:
			answers[color].append((color + 1, y))
			y += 1
	answers[color].append((color + 1, y))
	y += 1
for color in range(n):
	print(len(answers[color]))
	for (x, y) in answers[color]:
		print(x, y)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append([[i * n, i * n]])
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	if x > y:
		(x, y) = (y, x)
	a[x].append([x * n, x * n + y])
	a[y].append([y * n, x * n + y])
for i in range(n):
	print(len(a[i]))
	for j in a[i]:
		print(j[0] + 1, j[1] + 1)


(n, m) = list(map(int, input().split()))
t = [[] for i in range(n)]
cid = 1
for i in range(n):
	t[i].append(cid)
	cid += 1
for i in range(m):
	(a, b) = list(map(int, input().split()))
	t[a - 1].append(cid)
	t[b - 1].append(cid)
	cid += 1
for i in range(n):
	print(len(t[i]))
	for j in t[i]:
		print(i + 1, j)


(n, m) = map(int, input().split())
d = {}
conn = {}
pos = {}
for i in range(m):
	new = list(map(int, input().split()))
	new.sort()
	d[new[0]] = d.get(new[0], 0) + 1
	conn[new[0]] = conn.get(new[0], []) + [new[1]]
(x, y) = (1, 1)
for colour in d:
	y = colour
	tmpx = x
	for i in range(d[colour]):
		pos[colour] = pos.get(colour, []) + [(x, y)]
		x += 1
	for i in conn[colour]:
		pos[i] = pos.get(i, []) + [(tmpx, y + i - colour)]
		tmpx += 1
base = 10 ** 8
for i in range(1, n + 1):
	if i in pos:
		print(len(pos[i]))
		for j in pos[i]:
			print(*j)
	else:
		print(1)
		print(base, i)
		base += 1


(n, m) = map(int, input().split())
a = {q: [] for q in range(1, n + 1)}
for q in range(m):
	(x, y) = map(int, input().split())
	a[min(x, y)].append(max(y, x))
a = {q: sorted(a[q]) for q in range(1, n + 1)}
answer = [[] for q in range(1, n + 1)]
q2 = 1
for q in range(1, n + 1):
	for q1 in a[q]:
		answer[q1 - 1].append(q2)
		answer[q - 1].append(q2)
		q2 += 1
	answer[q - 1].append(q2)
	q2 += 1
for q in range(n):
	print(len(answer[q]))
	for q1 in answer[q]:
		print(q + 1, q1)


import sys

def main():
	input = sys.stdin.readline
	(N, M) = map(int, input().split())
	P = sorted([tuple(map(int, input().split())) for _ in range(M)])
	A = [[] for _ in range(N)]
	y = 1
	for (c1, c2) in P:
		A[c1 - 1].append((c1, y))
		A[c2 - 1].append((c2, y))
		y += 1
	for (c, ai) in enumerate(A):
		if ai:
			print(len(ai))
			for a in ai:
				print(*a)
		else:
			print(1)
			print(c + 1, y)
			y += 1
main()


(n, m) = map(int, input().split())
r = [[] for a in range(n)]
left = 0
for i in range(m):
	(a, b) = map(int, input().split())
	r[a - 1].append(left)
	r[b - 1].append(left)
	left += 1
for i in range(n):
	if len(r[i]) == 0:
		r[i].append(left)
		left += 1
	l = len(r[i])
	print(l)
	for j in range(l):
		print(i + 1, r[i][j] + 1)


from collections import namedtuple
Cell = namedtuple('Cell', ['row', 'col'])
(n, m) = map(int, input().split())
rooks = {}
row = 1
col = 1
for i in range(1, m + 1):
	(a, b) = map(int, input().split())
	if a not in rooks and b not in rooks:
		rooks[a] = [Cell(row=row, col=col)]
		rooks[b] = [Cell(row=row, col=col + 1)]
		row += 1
		col += 2
	elif a in rooks and b in rooks:
		last_a = rooks[a][-1]
		last_b = rooks[b][-1]
		rooks[a].append(Cell(row=row, col=last_a.col))
		rooks[b].append(Cell(row=row, col=last_b.col))
		row += 1
	else:
		if b in rooks:
			(a, b) = (b, a)
		last_a = rooks[a][-1]
		rooks[a].append(Cell(row=row, col=last_a.col))
		rooks[b] = [Cell(row=row, col=col)]
		row += 1
		col += 1
for i in range(1, n + 1):
	if i not in rooks:
		rooks[i] = [Cell(row=row, col=col)]
		row += 1
		col += 1
for i in range(1, n + 1):
	if i not in rooks:
		print(0)
	else:
		cells = rooks[i]
		print(len(cells))
		for cell in cells:
			print(cell.row, cell.col)


import math
(n, m) = list(map(int, input().split()))
hs = []
for _ in range(m):
	(a, b) = list(map(int, input().split()))
	a -= 1
	b -= 1
	hs.append((min(a, b), max(a, b)))
used = [0] * n
placed = [[] for _ in range(n)]
for (a, b) in hs:
	placed[a].append(b * n + used[b])
	used[b] += 1
for i in range(n):
	print(max(1, used[i]) + len(placed[i]))
	for j in range(max(1, used[i])):
		print(i * n + j + 1, i + 1)
	for j in placed[i]:
		print(j + 1, i + 1)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
a = [[] for i in range(n)]
for i in range(n):
	a[i].append((i + 1, i + 1))
c = n + 1
for i in range(m):
	(x, y) = map(int, input().split())
	a[x - 1].append((x, c))
	a[y - 1].append((y, c))
	c += 1
for i in a:
	print(len(i))
	for j in range(len(i)):
		print(*i[j])


(n, m) = [int(x) for x in input().strip().split(' ')]
data = [[] for _ in range(105)]
for i in range(1, m + 1):
	(a, b) = [int(x) for x in input().strip().split(' ')]
	data[a].append((a, a * n + b))
	data[b].append((b, a * n + b))
for i in range(1, n + 1):
	print(len(data[i]) + 1)
	print(i, i)
	for (a, b) in data[i]:
		print(a, b)


from sys import stdin, stdout
from math import sin, tan, cos
(n, m) = map(int, stdin.readline().split())
vertices = [[] for i in range(n + 1)]
cnt = [1 for i in range(n + 1)]
string = [0 for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, stdin.readline().split())
	if a < b:
		(a, b) = (b, a)
	vertices[a].append(b)
	cnt[b] += 1
positions = {}
cur = [1, 1]
for i in range(1, n + 1):
	positions[i] = []
	for j in range(cnt[i] - 1):
		positions[i].append(cur[:])
		cur[1] = cur[1] + 1
		positions[i].append(cur[:])
		cur[0] = cur[0] + 1
	positions[i].append(cur[:])
	string[i] = cur[0]
	cur[0] = cur[0] + 1
	cur[1] = cur[1] + 1
for i in range(1, n + 1):
	for v in vertices[i]:
		positions[i].append([string[v], string[i]])
		string[v] -= 1
cnt = 0
for i in range(1, n + 1):
	stdout.write(str(len(positions[i])) + '\n')
	for v in positions[i]:
		cnt += 1
		if cnt > 5000:
			while True:
				cnt += 1
		stdout.write(str(v[0]) + ' ' + str(v[1]) + '\n')


from collections import defaultdict

def read():
	return [int(v) for v in input().split()]

def main():
	(n, m) = read()
	c = defaultdict(list)
	for i in range(1, n + 1):
		c[i].append((i, i))
	for i in range(1, m + 1):
		colors = read()
		c[colors[0]].append((100 + 2 * i, colors[0] * 1000 + colors[1]))
		c[colors[0]].append((100 + 2 * i, colors[0]))
		c[colors[1]].append((100 + 2 * i + 1, colors[0] * 1000 + colors[1]))
		c[colors[1]].append((100 + 2 * i + 1, colors[1]))
	for i in range(1, n + 1):
		print(len(c[i]))
		for v in c[i]:
			print(v[0], v[1])
main()


a = list(map(int, input().split()))
n = a[0]
m = a[1]
b = list()
for j in range(m):
	b.append(list(map(int, input().split())))
ans = [] * n
for i in range(n):
	ans.append([])
for j in range(n):
	ans[j].append([j + 1, j + 1])
free = n + 1
for j in range(m):
	x = b[j][0]
	y = b[j][1]
	ans[x - 1].append([x, free])
	ans[y - 1].append([y, free])
	free = free + 1
for j in range(n):
	print(len(ans[j]))
	for i in range(len(ans[j])):
		print(ans[j][i][0], ans[j][i][1], sep=' ')


s = input().split()
n = int(s[0])
m = int(s[1])
col = []
for i in range(n):
	col.append([i])
t = n + 1
for i in range(m):
	s = input().split()
	a = int(s[0]) - 1
	b = int(s[1]) - 1
	col[a].append(t)
	col[b].append(t)
	t += 1
for i in range(len(col)):
	print(len(col[i]))
	for j in range(len(col[i])):
		print(i + 1, col[i][j] + 1)


(n, m) = map(int, input().split())
SAME = [list(map(int, input().split())) for i in range(m)]
C = [[] for i in range(n + 1)]
for i in range(len(SAME)):
	C[SAME[i][0]].append((i, 2 * i))
	C[SAME[i][1]].append((i, 2 * i + 1))
CONE = [[] for i in range(n + 1)]
for i in range(1, n + 1):
	for j in C[i]:
		CONE[i].append((1001 + i, j[1]))
for i in range(1, n + 1):
	CONE[i].append((1001 + i, 100000 + i))
for i in range(1, n + 1):
	print(len(C[i]) + len(CONE[i]))
	for (j, k) in C[i]:
		print(j + 1, k + 1)
	for (j, k) in CONE[i]:
		print(j + 1, k + 1)


import sys

def rint():
	return map(int, sys.stdin.readline().split())
(n, m) = rint()
hca = []
for i in range(m):
	(c1, c2) = rint()
	hca.append([c1, c2])
poc = [[] for i in range(n + 1)]
for i in range(1, m + 1):
	(c1, c2) = hca[i - 1]
	poc[c1].append([c1, i])
	poc[c2].append([c2, i])
j = m + 1
for i in range(1, n + 1):
	if len(poc[i]) == 0:
		poc[i].append([i, j])
		j += 1
for i in range(1, n + 1):
	print(len(poc[i]))
	for (x, y) in poc[i]:
		print(x, y)


(n, m) = map(int, input().split())
out = [[] for i in range(n)]
for i in range(n):
	out[i].append((i + 1, i + 1))
curr = n + 100
for j in range(m):
	(a, b) = map(int, input().split())
	out[a - 1].append((a, curr))
	out[b - 1].append((b, curr))
	curr += 1
for l in out:
	print(len(l))
	for (a, b) in l:
		print(a, b)


def main():
	(n, m) = map(int, input().split())
	rooks = [[(i, i)] for i in range(n)]
	edges = (tuple(map(int, input().split())) for _ in range(m))
	counter = n
	for (a, b) in edges:
		a -= 1
		b -= 1
		rooks[a].append((a, counter))
		rooks[b].append((b, counter))
		counter += 1
	for i in range(n):
		print(len(rooks[i]))
		for (x, y) in rooks[i]:
			print(x + 1, y + 1, sep=' ')
main()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
MOD = 1000000007

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

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, m) = value()
ans = defaultdict(list)
for i in range(n):
	ans[i + 1].append((i + 1, i + 1))
k = n + 1
for i in range(m):
	(x, y) = value()
	ans[x].append((k, x))
	ans[y].append((k, y))
	k += 1
for i in range(1, n + 1):
	print(len(ans[i]))
	for j in ans[i]:
		print(*j)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append([])
	a[i].append([i, i])
c = n
for i in range(m):
	(c1, c2) = map(int, input().split())
	a[c1 - 1].append([c1 - 1, c])
	a[c2 - 1].append([c2 - 1, c])
	c += 1
for z in a:
	print(len(z))
	for t in z:
		print(t[0] + 1, t[1] + 1)


(n, m) = map(int, input().split())
arr = []
for i in range(m):
	(x, y) = map(int, input().split())
	arr.append([x, y])
dict1 = {}
k = 1
for i in range(m):
	a = arr[i][0]
	b = arr[i][1]
	try:
		dict1[a].append((k, a))
	except:
		dict1[a] = [(k, a)]
	try:
		dict1[b].append((k, b))
	except:
		KeyError
		dict1[b] = [(k, b)]
	k += 1
for i in range(1, n + 1):
	try:
		z = len(dict1[i])
	except:
		KeyError
		dict1[i] = [(k, i)]
		k += 1
for i in range(1, n + 1):
	print(len(dict1[i]))
	for j in dict1[i]:
		print(j[0], j[1])


(n, m) = map(int, input().split())
d = {}
for i in range(1, n + 1):
	d[i] = set()
for i in range(m):
	(x, y) = map(int, input().split())
	d[x].add(x * n + y)
	d[y].add(x * n + y)
for i in range(1, n + 1):
	print(len(d[i]) + 1)
	print(i, i)
	for k in d[i]:
		print(i, k)


(n, m) = map(int, input().split())
a = [[] for i in range(n + 1)]
for i in range(m):
	(loc1, loc2) = map(int, input().split())
	a[loc1].append(loc2)
	a[loc2].append(loc1)
k = 1
cvaz = [0] * (n + 1)
for i in range(1, n + 1):
	l = len(a[i])
	print(l + 1)
	print(i, k)
	k += 1
	cvaz[i] = k
	for j in range(l):
		if a[i][j] > i:
			print(i, k)
			k += 1
		else:
			print(i, cvaz[a[i][j]])
			cvaz[a[i][j]] += 1


(n, m) = map(int, input().split())
ans = [[] for i in range(n)]
for i in range(n):
	ans[i].append((i + 1, i + 1))
g = [set() for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	ans[a].append((101 + i, a + 1))
	ans[b].append((101 + i, b + 1))
for i in range(n):
	print(len(ans[i]))
	for j in range(len(ans[i])):
		print(*ans[i][j])


(n, m) = map(int, input().split())
ans = [[[i, i]] for i in range(n + 1)]
j = n + 2
for i in range(m):
	(a, b) = map(int, input().split())
	s1 = [j, a]
	s2 = [j, b]
	ans[a].append(s1)
	ans[b].append(s2)
	j += 1
for i in range(1, n + 1):
	print(len(ans[i]))
	for j in ans[i]:
		print(j[0], j[1])


(n, m) = map(int, input().split())
color_pairs = [list(map(int, input().split())) for i in range(m)]
towers = [[(i, i)] for i in range(1, n + 1)]
last_coord = n + 1
for (c1, c2) in color_pairs:
	towers[c1 - 1].append((last_coord, c1))
	towers[c2 - 1].append((last_coord, c2))
	last_coord += 1
for i in range(len(towers)):
	print(len(towers[i]))
	for (x, y) in towers[i]:
		print(x, y)


from collections import Counter
(n, m) = [int(val) for val in input().split()]
harmony = [set([]) for i in range(n)]
for i in range(m):
	(a, b) = [int(val) for val in input().split()]
	a -= 1
	b -= 1
	harmony[a].add(b)
	harmony[b].add(a)
pos = [[] for i in range(n)]
v = 1
vertical_positions = {}
for i in range(n):
	s = harmony[i]
	count = len(s)
	vertical_positions[i] = set([])
	if count == 0:
		vertical_positions[i].add(v)
		pos[i].append((i + 1, v))
		v += 1
	else:
		for color in s:
			if color < i:
				val = vertical_positions[color].pop()
				pos[i].append((i + 1, val))
			else:
				vertical_positions[i].add(v)
				pos[i].append((i + 1, v))
				v += 1
for i in pos:
	print(len(i))
	for j in i:
		print(j[0], j[1])


import sys
fin = sys.stdin.readline
(n, m) = [int(elem) for elem in input().split(' ')]
harmonies = [[int(elem) for elem in fin().split(' ')] for _ in range(m)]
coords = {i: [(i, i)] for i in range(1, n + 1)}
for (i, (color1, color2)) in enumerate(harmonies, start=n + 1):
	coords[color1].append((color1, i))
	coords[color2].append((color2, i))
for i in range(1, n + 1):
	coords_each_color = coords[i]
	print(len(coords_each_color))
	for coord in coords_each_color:
		print(coord[0], coord[1])


(N, M) = map(int, input().split())
ans = [(0, 0)] + [[(i + 1, i + 10000)] for i in range(N)]
y = 9999
for mi in range(M):
	(u, v) = map(int, input().split())
	ans[u].append((u, y))
	ans[v].append((v, y))
	y -= 1
for i in range(1, N + 1):
	print(len(ans[i]))
	for (x, y) in ans[i]:
		print('{} {}'.format(x, y))


from collections import defaultdict

def compute(n, col_pairs):
	pos = defaultdict(list)
	res = defaultdict(list)
	for i in range(1, n + 1):
		pos[i].append((i, i))
	for (i, (u, v)) in enumerate(col_pairs, 1):
		res[u].append((u, n + i))
		res[v].append((v, n + i))
	for i in range(1, n + 1):
		if not res[i]:
			print(1)
			print(i, i)
		else:
			print(len(res[i]))
			for (p1, p2) in res[i]:
				print(p1, p2)

def run():
	(n, m) = [int(c) for c in input().split()]
	col_pairs = []
	for _ in range(m):
		(col1, col2) = [int(c) for c in input().split()]
		col_pairs.append((col1, col2))
	compute(n, col_pairs)
run()


(n, m) = map(int, input().split())
ans = [(i + 1, i + 1) for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	ans += [(n + i + 1, a), (n + i + 1, b)]
for color in range(n):
	ls = []
	for (a, b) in ans:
		if color + 1 == b:
			ls += [(a, b)]
	print(len(ls))
	for (a, b) in ls:
		print(a, b)


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
for i in range(1, n + 1):
	d[i].append((i, i))
cur = n + 1
for i in range(m):
	(a, b) = map(int, input().split())
	d[a].append((cur, a))
	d[b].append((cur, b))
	cur += 1
for i in d:
	print(len(d[i]))
	for j in d[i]:
		print(*j)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, color_pairs):
	result = {}
	for i in range(1, n + 1):
		result[i] = [[i, i]]
	i = n + 1
	for p in color_pairs:
		result[p[0]].append([i, p[0]])
		result[p[1]].append([i, p[1]])
		i += 1
	return result
(n, m) = arr_in()
color_pairs = mat_in(m)
result = solve(n, color_pairs)
for key in range(1, n + 1):
	out(len(result[key]))
	for item in result[key]:
		arr_out(item)


(n, m) = map(int, input().split())
edges = [[] for _ in range(n)]
for (edge_id, i) in enumerate(range(m)):
	(a, b) = map(int, input().split())
	edges[a - 1].append((b - 1, edge_id))
	edges[b - 1].append((a - 1, edge_id))
cnt = 0
ans = [[] for _ in range(n)]
for i in range(n):
	for (j, (node, edge_id)) in enumerate(edges[i]):
		cnt += 1
		ans[i].append((cnt, i + 1))
		ans[i].append((cnt, n + 1 + edge_id))
	if len(edges[i]) == 0:
		cnt += 1
		ans[i].append((cnt, i + 1))
print('\n'.join(('%d\n' % len(color) + '\n'.join(('%d %d' % (x, y) for (x, y) in color)) for color in ans)))


ans = [[] for i in range(1, 103)]
(U, V) = ([0 for i in range(1, 1003)], [0 for i in range(1, 1003)])
(n, m) = map(int, input().split())
for i in range(0, m):
	(u, v) = map(int, input().split())
	ans[u].append([u, i + n + 1])
	ans[v].append([v, i + n + 1])
for i in range(1, n + 1):
	ans[i] = ans[i] + [[i, i]]
for i in range(1, n + 1):
	print(len(ans[i]))
	for it in ans[i]:
		print(it[0], it[1])


import sys
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
mod = 10 ** 9 + 7

def main():
	(n, m) = map(int, input().split())
	harms = []
	for i in range(m):
		harms.append(list(map(int, input().split())))
	harms.sort()
	ans = []
	for i in range(n + 1):
		ans.append([[i, i]])
	j = 0
	c = 1
	for i in range(1, n + 1):
		while j < len(harms) and harms[j][0] == i:
			ans[i].append([n + c, i])
			ans[harms[j][1]].append([n + c, harms[j][1]])
			j += 1
			c += 1
	for i in range(1, n + 1):
		print(len(ans[i]))
		for j in ans[i]:
			print(*j)
main()


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
L = []
M = []
for i in range(101):
	L.append([])
	M.append([])
for i in range(m):
	(x, y) = input().split(' ')
	(x, y) = (int(x), int(y))
	if x > y:
		z = x
		x = y
		y = z
	L[x].append(y)
k = 1
for i in range(1, n + 1):
	if len(L[i]) == 0:
		M[i].append(k)
		k += 1
	else:
		for j in range(len(L[i])):
			M[i].append(k)
			M[L[i][j]].append(k)
			k += 1
for i in range(1, n + 1):
	print(len(M[i]))
	for j in range(len(M[i])):
		print(M[i][j], end=' ')
		print(i)


from collections import defaultdict

def main():
	(n, m) = [int(c) for c in input().split()]
	pos = defaultdict(list)
	for i in range(1, m + 1):
		(first, second) = [int(c) for c in input().split()]
		pos[first].append((first, n + i))
		pos[second].append((second, n + i))
	for i in range(1, n + 1):
		if not pos[i]:
			pos[i].append((i, i))
		print(len(pos[i]))
		for (p1, p2) in pos[i]:
			print(p1, p2)
main()


(n, m) = map(int, input().split())
ans = [[(i, i)] for i in range(n)]
k = n
for i in range(m):
	(a, b) = map(int, input().split())
	ans[a - 1].append((a - 1, k))
	ans[b - 1].append((b - 1, k))
	k += 1
for i in ans:
	print(len(i))
	for j in i:
		print(j[0] + 1, j[1] + 1)


from math import *
(n, m) = map(int, input().split())
ref = {i: set() for i in range(1, n + 1)}
for i in range(m):
	(a, b) = map(int, input().split())
	ref[a].add(a * n + b)
	ref[b].add(a * n + b)
for i in range(1, n + 1):
	y = len(ref[i]) + 1
	print(y)
	print(i, i)
	for j in ref[i]:
		print(i, j)


(n, m) = [int(x) for x in input().split(' ')]
positions_collection = []
for i in range(n):
	positions_collection.append([(i, i)])
for i in range(m):
	(f, t) = [int(x) - 1 for x in input().split(' ')]
	positions_collection[f].append((f, n + i))
	positions_collection[t].append((t, n + i))
for (e, q) in enumerate(positions_collection):
	print(len(q))
	for (c1, c2) in q:
		print(c1 + 1, c2 + 1)


(n, m) = [int(i) for i in input().split()]
harmonies = []
for i in range(m):
	harmonies.append([int(i) for i in input().split()])
rooks_by_colour = [[] for i in range(n + 1)]
for i in range(1, n + 1):
	rooks_by_colour[i].append((i, i))
next_row = n + 1
for harmony in harmonies:
	(colour1, colour2) = harmony
	rooks_by_colour[colour1].append((next_row, colour1))
	rooks_by_colour[colour2].append((next_row, colour2))
	next_row += 1
for i in range(1, n + 1):
	print(len(rooks_by_colour[i]))
	for i in rooks_by_colour[i]:
		print(i[0], i[1])


(n, m) = map(int, input().split())
j = 0
lis = [[] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	lis[a - 1].append(j + 1)
	lis[b - 1].append(j + 1)
	j += 1
for pos in range(n):
	if len(lis[pos]) > 0:
		print(len(lis[pos]))
		for i in lis[pos]:
			print(str(i), str(pos + 1))
	else:
		print(1)
		print(j + 1, pos + 1)
		j += 1


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, m) = map(int, input().split())
d = defaultdict(list)
t = n + 1
for i in range(m):
	(a, b) = map(int, input().split())
	d[a].append([t, a])
	d[b].append([t, b])
	t += 1
for i in range(n):
	print(len(d[i + 1]) + 1)
	print(i + 1, i + 1)
	for j in d[i + 1]:
		print(*j)


import sys
lines = sys.stdin.readlines()
(n, m) = map(int, lines[0].strip().split(' '))
curr = n
dic = {}
for i in range(1, m + 1):
	curr += 1
	(a, b) = map(int, lines[i].strip().split(' '))
	if a not in dic:
		dic[a] = []
	if b not in dic:
		dic[b] = []
	dic[a].append(curr)
	dic[b].append(curr)
for i in range(1, n + 1):
	if i not in dic:
		print(1)
	else:
		print(1 + len(dic[i]))
	print('{} {}'.format(i, i))
	if i in dic:
		for val in dic[i]:
			print('{} {}'.format(i, val))


(n, m) = map(int, input().split())
harmonies = []
for i in range(m):
	harmonies.append(list(map(int, input().split())))
spots = []
for i in range(n):
	yourspots = []
	for j in range(m):
		if i + 1 in harmonies[j]:
			yourspots.append((i + 1, j + 1))
	yourspots.append((i + 1, 10000 - i))
	spots.append(yourspots)
for i in range(n):
	print(len(spots[i]))
	for j in range(len(spots[i])):
		print(str(spots[i][j][0]), str(spots[i][j][1]))


(n, m) = map(int, input().split())
o = [[] for _ in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	o[a - 1].append('%i %i' % (a, i + 1))
	o[b - 1].append('%i %i' % (b, i + 1))
m += 1
for i in range(n):
	if len(o[i]) == 0:
		print(1)
		print('%i %i' % (i + 1, m))
		m += 1
	else:
		print(len(o[i]))
		print('\n'.join(o[i]))


(n, m) = list(map(int, input().split()))
G = [[] for _ in range(n + 1)]
final = [[] for _ in range(n + 1)]
seen = {}
for _ in range(m):
	(a, b) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	seen[a] = True
	seen[b] = True
	G[a].append(b)
step = 1
for i in range(1, n + 1):
	hrmny = G[i]
	if i not in seen:
		final[i].append((step, i))
		step += 1
	for h in hrmny:
		final[i].append((step, i))
		final[h].append((step, h))
		step += 1
for i in range(1, n + 1):
	f = final[i]
	print(len(f))
	print('\n'.join(map(lambda a: '{} {}'.format(*a), f)))


(n, m) = map(int, input().split())
color = [[] for i in range(n)]
notPut = {i for i in range(n)}
c = 1
ncopy = n
for i in range(m):
	(a, b) = map(int, input().split())
	if a - 1 in notPut:
		notPut.remove(a - 1)
	if b - 1 in notPut:
		notPut.remove(b - 1)
	color[a - 1].append((c, a))
	color[b - 1].append((c, b))
	c += 1
	n -= 2
for x in notPut:
	color[x].append((c, x + 1))
	c += 1
	n -= 1
for i in range(n):
	color[0].append((c, 0))
for i in range(ncopy):
	print(len(color[i]))
	for coord in color[i]:
		print(*coord)


(n, m) = map(int, input().split())
table = []
for i in range(0, n + 1):
	table.append([])
for i in range(0, n + 1):
	table[i].append([])
t = [0] * (n + 1)
i = m
while i != 0:
	(n1, n2) = map(int, input().split())
	if n1 > n2:
		(n1, n2) = (n2, n1)
	t[n1] += 1
	t[n2] += 1
	table[n1].append((n1 - 1) * n + n2)
	table[n2].append((n1 - 1) * n + n2)
	i -= 1
i = 1
while i != n + 1:
	t[i] += 1
	table[i].append((i - 1) * n + i)
	print(t[i])
	j = 1
	while j != t[i] + 1:
		print(i, table[i][j])
		j += 1
	i += 1


(n, m) = list(map(int, input().strip().split()))
graph = [set({}) for i in range(n + 1)]
for i in range(m):
	(a, b) = list(map(int, input().strip().split()))
	graph[min(a, b)].add(max(a, b))
points = [set({}) for i in range(n + 1)]
points_start = [-1 for i in range(n + 2)]
s = 1
for j in range(1, n + 1):
	i = graph[j]
	points_start[j] = s
	s += len(i) + 1
points_start[-1] = s
for i in range(1, n + 1):
	for d in range(points_start[i + 1] - points_start[i]):
		points[i].add((points_start[i] + d, i))
for (coord, edges) in enumerate(graph):
	if coord != 0:
		for (i, edge) in enumerate(edges):
			points[edge].add((points_start[coord] + i, edge))
for (coord, p) in enumerate(points):
	if coord != 0:
		print(len(p))
		for j in p:
			print(j[0], j[1])


(n, m) = map(int, input().split())
a = [[] for i in range(105)]
for i in range(1, m + 1):
	(u, v) = map(int, input().split())
	a[u].append([u, i])
	a[v].append([v, i])
t = m + 1
for i in range(1, n + 1):
	if len(a[i]) == 0:
		a[i].append([i, t])
		t += 1
for i in range(1, n + 1):
	print(len(a[i]))
	for j in a[i]:
		print(j[0], j[1])


(n, m) = [int(s) for s in input().split()]
near = [[] for i in range(101)]
pos = [[] for i in range(101)]
for i in range(m):
	(a, b) = [int(s) for s in input().split()]
	near[a].append(b)
	near[b].append(a)
cnt = 0
vis = [0] * (n + 1)
color = [0] * (n + 1)
color0 = 1
c = 1
for i in range(1, n + 1):
	if len(near[i]) == 0:
		pos[i].append(c)
		c += 1
		continue
	for s in near[i]:
		if s > i:
			pos[s].append(c)
			pos[i].append(c)
			c += 1
for i in range(1, n + 1):
	print(len(pos[i]))
	for s in pos[i]:
		print(i, s)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
(n, m) = mints()
a = []
p = [None] * n
for i in range(n):
	p[i] = []
for i in range(m):
	(x, y) = mints()
	p[x - 1].append((i + 1, x))
	p[y - 1].append((i + 1, y))
for i in range(n):
	p[i].append((m + 1 + i, i + 1))
for i in range(n):
	print(len(p[i]))
	for j in p[i]:
		print(*j)


(n, m) = map(int, input().split())
d = {i: set() for i in range(1, n + 1)}
for _ in range(m):
	(a, b) = map(int, input().split())
	d[a].add(b)
	d[b].add(a)
x = 1
c = {i: set() for i in range(1, n + 1)}
for i in range(1, n + 1):
	c[i].add((x, i))
	x += 1
	for j in c:
		if j < i and j in d[i]:
			c[j].add((x, j))
			c[i].add((x, i))
			x += 1
for i in c:
	print(len(c[i]))
	for j in c[i]:
		print(j[0], j[1])


(n, m) = map(int, input().split())
clr = [[] for i in range(n)]
for i in range(m):
	(a, b) = sorted(map(int, input().split()))
	a -= 1
	b -= 1
	clr[a].append(b)
ys = [-1 for i in range(n)]
result = [[] for i in range(n)]
global y, x
x = 1
y = 1

def visit(cur):
	global y, x
	y += 1
	result[cur].append((x, y))
	x += 1
	ys[cur] = y
	for adj in clr[cur]:
		if ys[adj] == -1:
			visit(adj)
		result[cur].append((x, ys[cur]))
		result[adj].append((x, ys[adj]))
		x += 1
for i in range(n):
	if ys[i] == -1:
		visit(i)
for i in range(n):
	print(len(result[i]))
	for j in result[i]:
		print(*j)


def print_return(func):

	def wrapper(*args, **kwargs):
		retval = func(*args, **kwargs)
		print(retval)
		return retval
	return wrapper

class Solve:

	@print_return
	def solve_a(lines=None):
		if lines is None:
			(n, m, k, l) = (int(x) for x in input().split())
		else:
			(n, m, k, l) = (int(x) for x in lines[0].split())
		x = k + l + m - 1
		x //= m
		if x * m > n:
			return -1
		return x

	@print_return
	def solve_b(lines=None):
		if lines is None:
			b = int(input())
		else:
			b = int(lines[0])
		divisors = set()
		for x in range(1, int(b ** 0.5) + 5):
			if b % x == 0:
				divisors.add(x)
				divisors.add(b // x)
		return len(divisors)

	@print_return
	def solve_c(lines=None):
		if lines is None:
			(n, m) = (int(x) for x in input().split())
			good_pairs = [tuple((int(x) for x in input().split())) for _ in range(m)]
		else:
			(n, m) = (int(x) for x in lines[0].split())
			good_pairs = [tuple((int(x) for x in lines[j + 1].split())) for j in range(m)]
		color___coors = [[]] + [[(x + 1, x + 1)] for x in range(n)]
		for col in range(n + 1, n + m + 1):
			(c1, c2) = good_pairs.pop()
			color___coors[c1].append((c1, col))
			color___coors[c2].append((c2, col))
		ans = ''
		for (color, coors) in enumerate(color___coors):
			if color == 0:
				continue
			curr_ans = str(len(coors)) + '\n'
			for coor in coors:
				curr_ans += '{} {}\n'.format(*coor)
			ans += curr_ans
		return ans

	@print_return
	def solve_d(lines=None):
		if lines is None:
			n = int(input())
			idx___val = [int(x) for x in input().split()]
		else:
			n = int(lines[0])
			idx___val = [int(x) for x in lines[1].split()]
Solve.solve_c()


import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

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

def ii():
	return int(input())
(n, m) = lii()
pairs = []
for i in range(m):
	pairs.append(lii())
rooks = {i: [(i, i)] for i in range(n)}
(x, y) = (n, n)
for each in pairs:
	(p, q) = each
	p -= 1
	q -= 1
	rooks[p].append([x, y])
	rooks[q].append([x + 1, y])
	rooks[p].append([p, y])
	rooks[q].append([q, y])
	x += 2
	y += 1
for (k, v) in rooks.items():
	print(len(v))
	for rook in v:
		print(rook[0] + 1, rook[1] + 1)


(n, m) = map(int, input().split())
res = [[(i + 1, 5001 + i)] for i in range(n)]
for i in range(m):
	(a, b) = map(int, input().split())
	res[a - 1].append((a, i + 1))
	res[b - 1].append((b, i + 1))
for i in range(n):
	print(len(res[i]))
	for p in res[i]:
		print(*p)