MOD = 998244353 N = int(input()) T = [None] * N V = [None] * N S = [0] * (N + 1) for i in range(N): T[i], V[i] = map(int, input().split()) T[i] %= MOD S[i + 1] = (S[i] + T[i]) % MOD ans = 0 for i in range(N): a = 0 a -= 3 * T[i] ** 2 % MOD * ((T[i] + 1) ** 2 % MOD) % MOD a += 2 * (S[N] - 3 * S[i]) * T[i] % MOD * (T[i] + 1) % MOD * (2 * T[i] + 1) % MOD a += 6 * (2 * S[N] * S[i] - 3 * S[i] ** 2 + S[N] + 1) % MOD * T[i] % MOD * (T[i] + 1) % MOD a += 12 * (S[N] * S[i] - S[i] ** 2 + S[N] + 1) % MOD * S[i] % MOD * T[i] % MOD ans += a % MOD * V[i] ans %= MOD ans = ans * pow(24, MOD - 2, MOD) % MOD print(ans)