import strutils, sequtils, deques, macros type stdinReader = object buf: Deque[string] func newStdinReader(): stdinReader = result = stdinReader(buf: initDeque[string]()) proc readString(sr: var stdinReader): string = if sr.buf.len == 0: sr.buf = stdin.readLine.split.toDeque sr.buf.popFirst proc readInt(sr: var stdinReader): int = readString(sr).parseInt func staticGet(over, i: auto): auto = quote do: `i` type SegmentTree[T] = object n: int data: seq[T] e: T func init[T](n: int, e: T): SegmentTree[T] = var n2 = 1 while n2 < n: n2 *= 2 SegmentTree[T](n: n2, data: newSeqWith[T](n2 * 2, e), e: e) proc build[T](st: var SegmentTree[T], a: seq[T]) = for i, x in a: st.data[i + st.n] = x for i in countdown(st.n - 1, 1): st.data[i] = st.data[i * 2] + st.data[i * 2 + 1] proc update[T](st: var SegmentTree[T], i: int, x: T) = var k = i + st.n st.data[k] = x while k > 1: k = k div 2 st.data[k] = st.data[k * 2] + st.data[k * 2 + 1] func query[T, U](st: SegmentTree[T], l: int, r: int, ls, rs: U): auto = var l = l + st.n r = r + st.n var ls = ls rs = rs while l < r: if (l and 1) == 1: ls = ls + st.data[l] l += 1 if (r and 1) == 1: r -= 1 rs = st.data[r] + rs l = l div 2 r = r div 2 ls + rs const MOD = 998244353 type Vec = array[6, int] type Matrix = array[6, array[6, int]] func `+`(a, b: Matrix): Matrix = # for i in 0 ..< a.len: # for j in 0..i: # for k in j..i: # result[i][j] = (result[i][j] + a[i][k] * b[k][j]) mod MOD result[0][0] = (result[0][0] + a[0][0] * b[0][0]) mod MOD result[1][0] = (result[1][0] + a[1][0] * b[0][0]) mod MOD result[1][0] = (result[1][0] + a[1][1] * b[1][0]) mod MOD result[1][1] = (result[1][1] + a[1][1] * b[1][1]) mod MOD result[2][0] = (result[2][0] + a[2][0] * b[0][0]) mod MOD result[2][0] = (result[2][0] + a[2][1] * b[1][0]) mod MOD result[2][0] = (result[2][0] + a[2][2] * b[2][0]) mod MOD result[2][1] = (result[2][1] + a[2][1] * b[1][1]) mod MOD result[2][1] = (result[2][1] + a[2][2] * b[2][1]) mod MOD result[2][2] = (result[2][2] + a[2][2] * b[2][2]) mod MOD result[3][0] = (result[3][0] + a[3][0] * b[0][0]) mod MOD result[3][0] = (result[3][0] + a[3][1] * b[1][0]) mod MOD result[3][0] = (result[3][0] + a[3][2] * b[2][0]) mod MOD result[3][0] = (result[3][0] + a[3][3] * b[3][0]) mod MOD result[3][1] = (result[3][1] + a[3][1] * b[1][1]) mod MOD result[3][1] = (result[3][1] + a[3][2] * b[2][1]) mod MOD result[3][1] = (result[3][1] + a[3][3] * b[3][1]) mod MOD result[3][2] = (result[3][2] + a[3][2] * b[2][2]) mod MOD result[3][2] = (result[3][2] + a[3][3] * b[3][2]) mod MOD result[3][3] = (result[3][3] + a[3][3] * b[3][3]) mod MOD result[4][0] = (result[4][0] + a[4][0] * b[0][0]) mod MOD result[4][0] = (result[4][0] + a[4][1] * b[1][0]) mod MOD result[4][0] = (result[4][0] + a[4][2] * b[2][0]) mod MOD result[4][0] = (result[4][0] + a[4][3] * b[3][0]) mod MOD result[4][0] = (result[4][0] + a[4][4] * b[4][0]) mod MOD result[4][1] = (result[4][1] + a[4][1] * b[1][1]) mod MOD result[4][1] = (result[4][1] + a[4][2] * b[2][1]) mod MOD result[4][1] = (result[4][1] + a[4][3] * b[3][1]) mod MOD result[4][1] = (result[4][1] + a[4][4] * b[4][1]) mod MOD result[4][2] = (result[4][2] + a[4][2] * b[2][2]) mod MOD result[4][2] = (result[4][2] + a[4][3] * b[3][2]) mod MOD result[4][2] = (result[4][2] + a[4][4] * b[4][2]) mod MOD result[4][3] = (result[4][3] + a[4][3] * b[3][3]) mod MOD result[4][3] = (result[4][3] + a[4][4] * b[4][3]) mod MOD result[4][4] = (result[4][4] + a[4][4] * b[4][4]) mod MOD result[5][0] = (result[5][0] + a[5][0] * b[0][0]) mod MOD result[5][0] = (result[5][0] + a[5][1] * b[1][0]) mod MOD result[5][0] = (result[5][0] + a[5][2] * b[2][0]) mod MOD result[5][0] = (result[5][0] + a[5][3] * b[3][0]) mod MOD result[5][0] = (result[5][0] + a[5][4] * b[4][0]) mod MOD result[5][0] = (result[5][0] + a[5][5] * b[5][0]) mod MOD result[5][1] = (result[5][1] + a[5][1] * b[1][1]) mod MOD result[5][1] = (result[5][1] + a[5][2] * b[2][1]) mod MOD result[5][1] = (result[5][1] + a[5][3] * b[3][1]) mod MOD result[5][1] = (result[5][1] + a[5][4] * b[4][1]) mod MOD result[5][1] = (result[5][1] + a[5][5] * b[5][1]) mod MOD result[5][2] = (result[5][2] + a[5][2] * b[2][2]) mod MOD result[5][2] = (result[5][2] + a[5][3] * b[3][2]) mod MOD result[5][2] = (result[5][2] + a[5][4] * b[4][2]) mod MOD result[5][2] = (result[5][2] + a[5][5] * b[5][2]) mod MOD result[5][3] = (result[5][3] + a[5][3] * b[3][3]) mod MOD result[5][3] = (result[5][3] + a[5][4] * b[4][3]) mod MOD result[5][3] = (result[5][3] + a[5][5] * b[5][3]) mod MOD result[5][4] = (result[5][4] + a[5][4] * b[4][4]) mod MOD result[5][4] = (result[5][4] + a[5][5] * b[5][4]) mod MOD result[5][5] = (result[5][5] + a[5][5] * b[5][5]) mod MOD func `+`(a: Vec, b: Matrix): Vec = # for i in 0 ..< a.len: # for j in 0..i: # result[j] = (result[j] + a[i] * b[i][j]) mod MOD result[0] = (result[0] + a[0] * b[0][0]) mod MOD result[0] = (result[0] + a[1] * b[1][0]) mod MOD result[1] = (result[1] + a[1] * b[1][1]) mod MOD result[0] = (result[0] + a[2] * b[2][0]) mod MOD result[1] = (result[1] + a[2] * b[2][1]) mod MOD result[2] = (result[2] + a[2] * b[2][2]) mod MOD result[0] = (result[0] + a[3] * b[3][0]) mod MOD result[1] = (result[1] + a[3] * b[3][1]) mod MOD result[2] = (result[2] + a[3] * b[3][2]) mod MOD result[3] = (result[3] + a[3] * b[3][3]) mod MOD result[0] = (result[0] + a[4] * b[4][0]) mod MOD result[1] = (result[1] + a[4] * b[4][1]) mod MOD result[2] = (result[2] + a[4] * b[4][2]) mod MOD result[3] = (result[3] + a[4] * b[4][3]) mod MOD result[4] = (result[4] + a[4] * b[4][4]) mod MOD result[0] = (result[0] + a[5] * b[5][0]) mod MOD result[1] = (result[1] + a[5] * b[5][1]) mod MOD result[2] = (result[2] + a[5] * b[5][2]) mod MOD result[3] = (result[3] + a[5] * b[5][3]) mod MOD result[4] = (result[4] + a[5] * b[5][4]) mod MOD result[5] = (result[5] + a[5] * b[5][5]) mod MOD func `+`(a: Matrix, b: Vec): Vec = # for i in 0 ..< a.len: # for j in 0..i: # result[i] = (result[i] + a[i][j] * b[j]) mod MOD result[0] = (result[0] + a[0][0] * b[0]) mod MOD result[1] = (result[1] + a[1][0] * b[0]) mod MOD result[1] = (result[1] + a[1][1] * b[1]) mod MOD result[2] = (result[2] + a[2][0] * b[0]) mod MOD result[2] = (result[2] + a[2][1] * b[1]) mod MOD result[2] = (result[2] + a[2][2] * b[2]) mod MOD result[3] = (result[3] + a[3][0] * b[0]) mod MOD result[3] = (result[3] + a[3][1] * b[1]) mod MOD result[3] = (result[3] + a[3][2] * b[2]) mod MOD result[3] = (result[3] + a[3][3] * b[3]) mod MOD result[4] = (result[4] + a[4][0] * b[0]) mod MOD result[4] = (result[4] + a[4][1] * b[1]) mod MOD result[4] = (result[4] + a[4][2] * b[2]) mod MOD result[4] = (result[4] + a[4][3] * b[3]) mod MOD result[4] = (result[4] + a[4][4] * b[4]) mod MOD result[5] = (result[5] + a[5][0] * b[0]) mod MOD result[5] = (result[5] + a[5][1] * b[1]) mod MOD result[5] = (result[5] + a[5][2] * b[2]) mod MOD result[5] = (result[5] + a[5][3] * b[3]) mod MOD result[5] = (result[5] + a[5][4] * b[4]) mod MOD result[5] = (result[5] + a[5][5] * b[5]) mod MOD func `+`(a, b: Vec): int = # for i in 0..