#P1951. [Aboi 2077] SL2(Z/NZ)

[Aboi 2077] SL2(Z/NZ)

Description

Count the number of 2×22 \times 2 matrices with determinant equal to 11 modulo NN.

That is:

$$\sum_{a=0}^{N-1}\sum_{b=0}^{N-1}\sum_{c=0}^{N-1}\sum_{d=0}^{N-1}[ad-bc\equiv1\ (\bmod\ N)]$$

Input Format

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

Then TT lines follow, each containing a positive integer NN, the modulus for that test.

Output Format

For each test case, output the answer modulo 998244353998244353.

10
2
5
11
23
101
64
128
114514
1919810
1145141919810
6
120
1320
12144
1030200
196608
1572864
173069674
546691096
761755430

Hint

Subtask ID NN Score
1 50\le 50 10
2 200\le 200
3 103\le 10^3 20
4 106\le 10^6
5 109\le 10^9
6 1018\le 10^{18}

For all testdata, 1T101 \le T \le 10, 1N10181 \le N \le 10^{18}.

Translated by ChatGPT 5