n = int(eval(input()))

A = [[int(i) for i in input().split()] for i in range(n)]



x, y = 1, 1

for i in range(n):

    a, b = A[i]

    m = max(-(-x // a), -(-y // b))

    x, y = a * m, b * m

    #print(x, y)

        

print((x + y))
n = int(eval(input()))

A = [[int(i) for i in input().split()] for i in range(n)]



x, y = A[0]

for a, b in A[1:]:

    m = max(-(-x // a), -(-y // b))

    x = a * m

    y = b * m

    #print(x, y)

        

print((x + y))
n = int(eval(input()))
A = [[int(i) for i in input().split()] for i in range(n)]
x, y = 1, 1
for i in range(n):
    a, b = A[i]
    m = max(-(-x // a), -(-y // b))
    x, y = a * m, b * m
    # print(x, y)
print((x + y))

n = int(eval(input()))
A = [[int(i) for i in input().split()] for i in range(n)]
x, y = A[0]
for a, b in A[1:]:
    m = max(-(-x // a), -(-y // b))
    x = a * m
    y = b * m
    # print(x, y)
print((x + y))

-x, y = 1, 1 -for i in range(n): -    a, b = A[i] +x, y = A[0] +for a, b in A[1:]: -    x, y = a * m, b * m +    x = a * m +    y = b * m