from random import randint
k = int(input())
width = randint(4, 10)
ls = [[randint(1, 100) for _ in range(width)] for _ in range(randint(3, 10))]
[print(i) for i in ls]
print()
for i in range(1, len(ls), 2):
for j in range(k):
ls[i].insert(0, ls[i].pop())
from random import randint
k = int(input())
width = randint(4, 10)
ls = [[randint(1, 100) for _ in range(width)] for _ in range(randint(3, 10))]
[print(i) for i in ls]
print()
for i in range(1, len(ls), 2):
for j in range(k):
ls[i].insert(0, ls[i].pop())
[print(i) for i in ls]