d, n = 0, 1
for _ in range(int(input())):
num = list(map(int, input().split()))
n = int(n * num[1] / num[0])
d = (d + num[2]) % 2
print(d, n)
d, n = 0, 1
for _ in range(int(input())):
num = list(map(int, input().split()))
n = int(n * num[1] / num[0])
d = (d + num[2]) % 2
print(d, n)