M = int(eval(input()))

DC = [tuple(map(int,input().split())) for i in range(M)]



sumd = sumc = 0

for d,c in DC:

    sumd += d*c

    sumc += c



ans = sumc-1 + (sumd-1)//9

print(ans)
M = int(eval(input()))

DC = [tuple(map(int,input().split())) for i in range(M)]

s = k = 0

for d,c in DC:

    k += c

    s += d*c

ans = k-1 + (s-1)//9

print(ans)
M = int(eval(input()))
DC = [tuple(map(int, input().split())) for i in range(M)]
sumd = sumc = 0
for d, c in DC:
    sumd += d * c
    sumc += c
ans = sumc - 1 + (sumd - 1) // 9
print(ans)

M = int(eval(input()))
DC = [tuple(map(int, input().split())) for i in range(M)]
s = k = 0
for d, c in DC:
    k += c
    s += d * c
ans = k - 1 + (s - 1) // 9
print(ans)

-sumd = sumc = 0 +s = k = 0 -    sumd += d * c -    sumc += c -ans = sumc - 1 + (sumd - 1) // 9 +    k += c +    s += d * c +ans = k - 1 + (s - 1) // 9