M = int(eval(input()))

D = []

C = []

for i in range(M):

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

    D.append(d)

    C.append(c)



ans = 0

n = D[0]

C[0] -= 1

for i in range(M):

    c = C[i]

    d = D[i]

    while c != 0:

        if c%2==0:

            ans += c//2*((2*d)//10+1)

            d = (2*d)//10+(2*d)%10

            c //= 2

        else:

            ans += c//2*((2*d)//10+1)

            ans += (n+d)//10+1

            n = (n+d)//10+(n+d)%10

            d = (2*d)//10+(2*d)%10

            c //= 2

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

D = 0

S = 0

for i in range(M):

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

    D += d

    S += c*d

print((D-1+(S-1)//9))
M = int(eval(input()))
D = []
C = []
for i in range(M):
    d, c = list(map(int, input().split()))
    D.append(d)
    C.append(c)
ans = 0
n = D[0]
C[0] -= 1
for i in range(M):
    c = C[i]
    d = D[i]
    while c != 0:
        if c % 2 == 0:
            ans += c // 2 * ((2 * d) // 10 + 1)
            d = (2 * d) // 10 + (2 * d) % 10
            c //= 2
        else:
            ans += c // 2 * ((2 * d) // 10 + 1)
            ans += (n + d) // 10 + 1
            n = (n + d) // 10 + (n + d) % 10
            d = (2 * d) // 10 + (2 * d) % 10
            c //= 2
print(ans)

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

-D = [] -C = [] +D = 0 +S = 0 -    d, c = list(map(int, input().split())) -    D.append(d) -    C.append(c) -ans = 0 -n = D[0] -C[0] -= 1 -for i in range(M): -    c = C[i] -    d = D[i] -    while c != 0: -        if c % 2 == 0: -            ans += c // 2 * ((2 * d) // 10 + 1) -            d = (2 * d) // 10 + (2 * d) % 10 -            c //= 2 -        else: -            ans += c // 2 * ((2 * d) // 10 + 1) -            ans += (n + d) // 10 + 1 -            n = (n + d) // 10 + (n + d) % 10 -            d = (2 * d) // 10 + (2 * d) % 10 -            c //= 2 -print(ans) +    c, d = list(map(int, input().split())) +    D += d +    S += c * d +print((D - 1 + (S - 1) // 9))