#P7817. [RC-05] 迷失自我

[RC-05] 迷失自我

Description

For two digit strings S,TS, T consisting only of 7,97,9, if:

  • The lengths of S,TS, T are both nn.
  • The lexicographical order of SS is smaller than TT.
  • For any [l1,r1][l_1, r_1] and [l2,r2][l_2, r_2] (1l1r1n1 \le l_1 \le r_1 \le n, 1l2r2n1 \le l_2 \le r_2 \le n, where l1,r1,l2,r2l_1, r_1, l_2, r_2 are integers, and the two intervals are different), let ASA_S be the decimal number formed by arranging the characters of SS from position l1l_1 to r1r_1 in order, ATA_T be the decimal number formed by arranging the characters of TT from position l1l_1 to r1r_1 in order, BSB_S be the decimal number formed by arranging the characters of SS from position l2l_2 to r2r_2 in order, and BTB_T be the decimal number formed by arranging the characters of TT from position l2l_2 to r2r_2 in order. Then gcd(AS,BS)=gcd(AT,BT)\gcd(A_S, B_S) = \gcd(A_T, B_T).

Then (S,T)(S, T) is called an indistinguishable pair. For example, S=7977S = 7977 and T=7979T = 7979 are not an indistinguishable pair, because taking [l1,r1]=[1,4][l_1, r_1] = [1, 4] and [l2,r2]=[2,2][l_2, r_2] = [2, 2], we have gcd(AS,BS)=gcd(7977,9)=3\gcd(A_S, B_S) = \gcd(7977, 9) = 3 and gcd(AT,BT)=gcd(7979,9)=1\gcd(A_T, B_T) = \gcd(7979, 9) = 1, so 313 \ne 1.

Find how many indistinguishable pairs there are among length nn digit strings consisting only of 7,97,9. You only need to output the answer modulo 998244353998244353.

Input Format

This problem has multiple test cases within a single test point.

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

Each of the next TT lines contains one integer nn, the query.

Output Format

Output TT lines, each containing one integer: the answer for that test case modulo 998244353998244353.

1
1
1

Hint

For all testdata, 1T1041 \le T \le 10^4, 1n10181 \le n \le 10^{18}.

The detailed Constraints are as follows:

Test Point ID nn TT Score
11 10\le 10 22
22 1018\le 10^{18} 104\le 10^4 9898

Translated by ChatGPT 5