M = int(eval(input()))

ans = 0



c1 = []

for _ in range(M):

    d, c = list(map(int, input().split()))

    v1 = ((d*c)//9)-((d*c)%9==0 and d*c>0)

    v2 = c-1

    ans += v1+v2

    c1.append(d*c-9*v1)



ans += M-1

s = sum(c1)

ans += (s//9)-(s%9==0 and s>0)

print(ans)

M = int(eval(input()))

ans, s = 0, 0



for _ in range(M):

    d, c = list(map(int, input().split()))

    s += d*c

    ans += c



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

print(ans)

M = int(eval(input()))
ans = 0
c1 = []
for _ in range(M):
    d, c = list(map(int, input().split()))
    v1 = ((d * c) // 9) - ((d * c) % 9 == 0 and d * c > 0)
    v2 = c - 1
    ans += v1 + v2
    c1.append(d * c - 9 * v1)
ans += M - 1
s = sum(c1)
ans += (s // 9) - (s % 9 == 0 and s > 0)
print(ans)

M = int(eval(input()))
ans, s = 0, 0
for _ in range(M):
    d, c = list(map(int, input().split()))
    s += d * c
    ans += c
ans += (s - 1) // 9 - 1
print(ans)

-ans = 0 -c1 = [] +ans, s = 0, 0 -    v1 = ((d * c) // 9) - ((d * c) % 9 == 0 and d * c > 0) -    v2 = c - 1 -    ans += v1 + v2 -    c1.append(d * c - 9 * v1) -ans += M - 1 -s = sum(c1) -ans += (s // 9) - (s % 9 == 0 and s > 0) +    s += d * c +    ans += c +ans += (s - 1) // 9 - 1