import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 def f(a, b, c, x, y): res = a*(x & y)+b*(x | y)+c*(x ^ y) return res%4 # return bin(res%4)[2:].zfill(2) # for a in range(4): # for b in range(4): # for c in range(4): # pDB(f"a={a},b={b},c={c}") # cur = [[0]*4 for _ in range(4)] # for x in range(4): # for y in range(4): # cur[x][y] = f(a, b, c, x, y) # p2D(cur) to = [[-1]*4 for _ in range(4)] ot = [[set() for _ in range(4)] for _ in range(4)] n, a, b, c = LI() for x in range(4): for y in range(4): to[x][y] = f(a, b, c, x, y) ot[to[x][y]][x].add(y) ot[to[x][y]][y].add(x) # p2D(to) # p2D(ot) dp = [[[0]*4 for _ in range(4)] for _ in range(4)] for i in range(4): for s in range(4): for j in ot[s][i]: dp[i][j][s] = 1 # p2D(dp) for _ in range(n-2): ndp = [[[0]*4 for _ in range(4)] for _ in range(4)] for i in range(4): for j in range(4): for s in range(4): pre = dp[i][j][s] if pre == 0: continue for x in range(4): ni = to[i][x] for nj in ot[j][x]: ndp[ni][nj][s] += pre ndp[ni][nj][s] %= md dp = ndp ans = 0 for i in range(4): for j in range(4): for s in range(4): if to[i][j] == s: ans += dp[i][j][s] ans %= md print(ans)