def steps(c, s):

    # c: No. of elements,  s: sum of elements

    q, r = divmod(s, 9)

    if r != 0:

        cnt = (c-1) + q

    else:

        cnt = (c-1) + q-1

        r = 9

    return cnt, r



m = int(eval(input()))

r0 = 0; ans = 0   

for _ in range(m):

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

    cnt, r = steps(c, d*c)

    ans += cnt

    cnt, r0 = steps(2, r0+r)

    ans += cnt

print((ans-1))
def steps(c, s):

    # c: No. of elements,  s: sum of elements

    q, r = divmod(s, 9)

    if r != 0:

        cnt = (c-1) + q

    else:

        cnt = (c-1) + q-1

        r = 9

    return cnt, r



m = int(eval(input()))

tot_c, tot_s = 0, 0

for _ in range(m):

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

    tot_c += c

    tot_s += c*d



ans, r = steps(tot_c, tot_s)

print(ans)
def steps(c, s):
    # c: No. of elements,  s: sum of elements
    q, r = divmod(s, 9)
    if r != 0:
        cnt = (c - 1) + q
    else:
        cnt = (c - 1) + q - 1
        r = 9
    return cnt, r


m = int(eval(input()))
r0 = 0
ans = 0
for _ in range(m):
    d, c = list(map(int, input().split()))
    cnt, r = steps(c, d * c)
    ans += cnt
    cnt, r0 = steps(2, r0 + r)
    ans += cnt
print((ans - 1))

def steps(c, s):
    # c: No. of elements,  s: sum of elements
    q, r = divmod(s, 9)
    if r != 0:
        cnt = (c - 1) + q
    else:
        cnt = (c - 1) + q - 1
        r = 9
    return cnt, r


m = int(eval(input()))
tot_c, tot_s = 0, 0
for _ in range(m):
    d, c = list(map(int, input().split()))
    tot_c += c
    tot_s += c * d
ans, r = steps(tot_c, tot_s)
print(ans)

-r0 = 0 -ans = 0 +tot_c, tot_s = 0, 0 -    cnt, r = steps(c, d * c) -    ans += cnt -    cnt, r0 = steps(2, r0 + r) -    ans += cnt -print((ans - 1)) +    tot_c += c +    tot_s += c * d +ans, r = steps(tot_c, tot_s) +print(ans)