N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A = [AB[i][0] for i in range(N)]
B = [AB[i][1] for i in range(N)]
mod = 998244353
dp = [[0, 0] for _ in range(N + 1)]
dp[0][0] = 1
dp[0][1] = 1
for i in range(1, N):
# 1つ前の表-表
if A[i - 1] != A[i]:
dp[i][0] += dp[i - 1][0]
# 1つ前の表-裏
if A[i - 1] != B[i]:
dp[i][1] += dp[i - 1][0]
# 1つ前の裏-表
if B[i - 1] != A[i]:
dp[i][0] += dp[i - 1][1]
# 1つ前の裏-裏
if B[i - 1] != B[i]:
dp[i][1] += dp[i - 1][1]
# 途中で値が大きくなりすぎないようにあまりを計算しておく
dp[i][0] %= mod
dp[i][1] %= mod
print(sum(dp[N - 1]) % mod)