m = int(eval(input()))

csum = 0

dsum = 0

for i in range(m):

  d,c = (int(x) for x in input().split())

  csum += c

  dsum += d*c

print((csum-1 + (dsum-1) // 9))

m = int(eval(input()))

csum = 0

dsum = 0

for i in range(m):

  c = [int(x) for x in input().split()]

  csum += c[1]

  dsum += c[0]*c[1]

print((csum-1 + (dsum-1) // 9))

m = int(eval(input()))
csum = 0
dsum = 0
for i in range(m):
    d, c = (int(x) for x in input().split())
    csum += c
    dsum += d * c
print((csum - 1 + (dsum - 1) // 9))

m = int(eval(input()))
csum = 0
dsum = 0
for i in range(m):
    c = [int(x) for x in input().split()]
    csum += c[1]
    dsum += c[0] * c[1]
print((csum - 1 + (dsum - 1) // 9))

-    d, c = (int(x) for x in input().split()) -    csum += c -    dsum += d * c +    c = [int(x) for x in input().split()] +    csum += c[1] +    dsum += c[0] * c[1]