MOD = 998244353 m = int(input()) V = [0] * m L = [0] * m for i in range(m): V[i], L[i] = map(int, input().split()) n = sum(L) if n <= 2: S = "" for v, l in zip(V, L): S += str(v) * l ans = 0 for i in range(1, int(S) + 1): if i % 15 == 0: ans += 8 elif i % 3 == 0 or i % 5 == 0: ans += 4 else: ans += len(str(i)) print(ans) exit() inv9 = pow(9, -1, MOD) S = 96 S += 480 * ((pow(10, n - 3, MOD) - 1) * inv9 % MOD) S -= ((n - 1) * 48 % MOD) * pow(10, n - 2, MOD) S %= MOD S *= -inv9 S %= MOD S += 25 S -= 4 S += 192 * (pow(10, n - 2, MOD) - 1) * inv9 S %= MOD times = 0 for v, l in zip(V, L): times *= pow(10, l, MOD) times += v * (pow(10, l, MOD) - 1) * inv9 times %= MOD S += (times - pow(10, n - 1, MOD) + 1) * (n % MOD) % MOD S %= MOD d = times - pow(10, n - 1, MOD) f = V[-1] % 5 five = (d - f) * pow(5, -1, MOD) % MOD five += 1 S += five * (4 - n) t = sum(l * v for l, v in zip(L, V)) % 3 three = (d - t + 1) * pow(3, -1, MOD) % MOD S += three * (4 - n) x = 0 while x % 3 != t or x % 5 != f: x += 1 fifteen = (d - x + 10) * pow(15, -1, MOD) % MOD S += fifteen * n S %= MOD print(S % MOD)