from random import randint
n = int(input())
a = [randint(1,99) for i in range(n)]
a3 = [a[i] for i in range(n) if a[i] % 3 == 0]
a5 = [a[i] for i in range(n) if a[i] % 5 == 0]
print(a,a3,a5,sep="\n")
from random import randint
n = int(input())
a = [randint(1,99) for i in range(n)]
a3 = [a[i] for i in range(n) if a[i] % 3 == 0]
a5 = [a[i] for i in range(n) if a[i] % 5 == 0]
print(a,a3,a5,sep="\n")