N = int(eval(input()))

ratio = [tuple(map(int, input().split())) for _ in range(N)]

t,a = 1,1



for nt,na in ratio:

    if nt<t or na<a:

        r = max((t-1)//nt+1, (a-1)//na+1)

        nt *= r

        na *= r

    t,a = nt,na

    #print(t, a)

print((t+a))

N = int(eval(input()))

ratio = [tuple(map(int, input().split())) for _ in range(N)]

t,a = 1,1



for nt,na in ratio:

    if nt<t or na<a:

        r = max(-(-t//nt), -(-a//na))

        nt *= r

        na *= r

    t,a = nt,na

    #print(t, a)

print((t+a))

N = int(eval(input()))
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for nt, na in ratio:
    if nt < t or na < a:
        r = max((t - 1) // nt + 1, (a - 1) // na + 1)
        nt *= r
        na *= r
    t, a = nt, na
    # print(t, a)
print((t + a))

N = int(eval(input()))
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for nt, na in ratio:
    if nt < t or na < a:
        r = max(-(-t // nt), -(-a // na))
        nt *= r
        na *= r
    t, a = nt, na
    # print(t, a)
print((t + a))

-        r = max((t - 1) // nt + 1, (a - 1) // na + 1) +        r = max(-(-t // nt), -(-a // na))