m=int(eval(input()))

d,c=[],[]

ans=-1

for i in range(m):

  dd,cc=list(map(int,input().split()))

  d.append(dd)

  c.append(cc)

  ans+=cc

a=0

for i in range(m):

  a+=d[i]*c[i]

  dd=(a-1)//9

  ans+=dd

  a-=dd*9

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

d=c=-1

for _ in range(m):

  dd,cc=list(map(int,input().split()))

  d+=dd*cc

  c+=cc

print((c+d//9))
m = int(eval(input()))
d, c = [], []
ans = -1
for i in range(m):
    dd, cc = list(map(int, input().split()))
    d.append(dd)
    c.append(cc)
    ans += cc
a = 0
for i in range(m):
    a += d[i] * c[i]
    dd = (a - 1) // 9
    ans += dd
    a -= dd * 9
print(ans)

m = int(eval(input()))
d = c = -1
for _ in range(m):
    dd, cc = list(map(int, input().split()))
    d += dd * cc
    c += cc
print((c + d // 9))

-d, c = [], [] -ans = -1 -for i in range(m): +d = c = -1 +for _ in range(m): -    d.append(dd) -    c.append(cc) -    ans += cc -a = 0 -for i in range(m): -    a += d[i] * c[i] -    dd = (a - 1) // 9 -    ans += dd -    a -= dd * 9 -print(ans) +    d += dd * cc +    c += cc +print((c + d // 9))