m=int(eval(input()))

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



D,S=0,0

for d,c in DC:

    D +=c

    S +=d*c

print((D-1+(S-1)//9))
n=int(eval(input()))

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



D,S=0,0

for d,c in DC:

    D +=c

    S +=d*c

print((D-1+(S-1)//9))
m = int(eval(input()))
DC = [list(map(int, input().split())) for _ in range(m)]
D, S = 0, 0
for d, c in DC:
    D += c
    S += d * c
print((D - 1 + (S - 1) // 9))

n = int(eval(input()))
DC = [list(map(int, input().split())) for _ in range(n)]
D, S = 0, 0
for d, c in DC:
    D += c
    S += d * c
print((D - 1 + (S - 1) // 9))

-m = int(eval(input())) -DC = [list(map(int, input().split())) for _ in range(m)] +n = int(eval(input())) +DC = [list(map(int, input().split())) for _ in range(n)]