#P8005. An Extra Requirement

An Extra Requirement

Description

Given a permutation PP of length NN, you may perform the following operation any number of times: choose three positions x,y,z (x<y<z)x, y, z \ (x<y<z). If Py<min{Px,Pz}P_y<\min\{P_x,P_z\} or Py>max{Px,Pz}P_y>\max\{P_x,P_z\}, then you may delete PyP_y.

Count the number of permutations PP for which there exists a way to delete elements so that in the end there are at most two numbers left and P1=AP_1=A. Since the answer may be very large, output the result modulo 998244353998244353.

Input Format

The first line contains a positive integer TT, the number of test cases.

The next TT lines each contain two positive integers N,AN, A, representing the length of the permutation PP and the first number of the permutation, respectively.

Output Format

Output TT lines, each containing one integer, the answer modulo 998244353998244353.

7
3 1
3 2
3 3
4 1
4 2
4 3
4 4
1
2
1
3
5
5
3
5
5 2
6 3
7 4
8 5
9 6
20
104
648
4662
38040

Hint

This problem uses bundled testdata.

Subtask ID Score Special Constraints
00 1010 T,N8T,N\le 8
11 1515 T5T\le 5N100N\le 100
22 1010 T5T\le 5N1000N\le 1000
33 1515 A=1A=1
44 T5T\le 5N5×104N\le 5\times 10^4
55 T200T\le 200
66 2020 No special constraints.

For all testdata, it is guaranteed that 1T1051\le T\le 10^5 and 1AN1051\le A\le N\le 10^5.

Translated by ChatGPT 5