n = int(eval(input()))

Ratio = [list(map(int,input().split())) for _ in range(n)]

t,a = 1,1



for i in range(n):

    x = max((t+Ratio[i][0]-1)//Ratio[i][0],(a+Ratio[i][1]-1)//Ratio[i][1])

    t,a = Ratio[i][0]*x,Ratio[i][1]*x

print((int(t+a)))
n = int(eval(input()))

Ratio = [list(map(int,input().split())) for _ in range(n)]

t,a = Ratio[0][0],Ratio[0][1]



for i in range(1,n):

    x = max((t+Ratio[i][0]-1)//Ratio[i][0],(a+Ratio[i][1]-1)//Ratio[i][1])

    t,a = Ratio[i][0]*x,Ratio[i][1]*x

print((int(t+a)))
n = int(eval(input()))
Ratio = [list(map(int, input().split())) for _ in range(n)]
t, a = 1, 1
for i in range(n):
    x = max((t + Ratio[i][0] - 1) // Ratio[i][0], (a + Ratio[i][1] - 1) // Ratio[i][1])
    t, a = Ratio[i][0] * x, Ratio[i][1] * x
print((int(t + a)))

n = int(eval(input()))
Ratio = [list(map(int, input().split())) for _ in range(n)]
t, a = Ratio[0][0], Ratio[0][1]
for i in range(1, n):
    x = max((t + Ratio[i][0] - 1) // Ratio[i][0], (a + Ratio[i][1] - 1) // Ratio[i][1])
    t, a = Ratio[i][0] * x, Ratio[i][1] * x
print((int(t + a)))

-t, a = 1, 1 -for i in range(n): +t, a = Ratio[0][0], Ratio[0][1] +for i in range(1, n):