atcoder#AGC054E. [AGC054E] ZigZag Break

[AGC054E] ZigZag Break

Score : 12001200 points

Problem Statement

Given are integers NN and AA. Find the number, modulo 998244353998244353, of permutations P=(P1,P2,,PN)P=(P_1,P_2,\cdots,P_N) of (1,2,,N)(1,2,\cdots,N) that satisfy the following conditions.

  • P1=AP_1=A.
  • It is possible to repeat the following operation so that PP has just two elements.- Choose three consecutive elements xx, yy, and zz. Here, y<min(x,z)y<\min(x,z) or y>max(x,z)y>\max(x,z) must hold. Then, erase yy from PP.
  • Choose three consecutive elements xx, yy, and zz. Here, y<min(x,z)y<\min(x,z) or y>max(x,z)y>\max(x,z) must hold. Then, erase yy from PP.

Solve TT test cases in an input file.

Constraints

  • 1T5×1051 \leq T \leq 5 \times 10^5
  • 3N1063 \leq N \leq 10^6
  • 1AN1 \leq A \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

TT

case1case_1

case2case_2

\vdots

caseTcase_T

Each case is in the following format:

NN AA

Output

Print the answer for each test case.

8
3 1
3 2
3 3
4 1
4 2
4 3
4 4
200000 10000
1
2
1
3
5
5
3
621235018

When N=4,A=2N=4,A=2, one permutation that satisfies the condition is P=(2,1,4,3)P=(2,1,4,3). One way to make it have just two elements is as follows.

  • Choose (x,y,z)=(2,1,4)(x,y,z)=(2,1,4) to erase 11, resulting in P=(2,4,3)P=(2,4,3).
  • Choose (x,y,z)=(2,4,3)(x,y,z)=(2,4,3) to erase 44, resulting in P=(2,3)P=(2,3).