# 4646 爬树的甲壳虫
# 数论的困难题 QAQ
# 重要的是公式的推导
n = int(input())
N = n
res = 0
p = 998244353
def qmi(a, b):
res = 1
while(b):
if b & 1:
res = res * a % p
a = a * a % p
b >>= 1
return res
while(N):
a, b = map(int, input().split())
res = (1 + res) * b % p * qmi((b - a), p - 2) % p
N -= 1
print(res)