#P9865. B. Random Nim Game

B. Random Nim Game

B. Random Nim Game

Problem Description

Nim is a two-player mathematic game of strategy in which players take turns removing stones from distinct heaps. On each turn, a player must remove at least one stone, and may remove any number of stones provided they all come from the same heap. The person who makes the last move (i.e., who takes the last stone) wins. Alice and Bob is tired of playing Nim under the standard rule, so they want to play Nim randomly. On each turn, a player must select any one of the heaps. Assuming the heap he selects contains xx stones, he will randomly choose a integer number yy from [1,x][1, x], and remove yy stone(s) from the heap. Note that the selected heap can be arbitrary. Alice will play first. Calculate the probability of Alice winning, modulo 998244353998244353.

Input

The input consists of multiple test cases. The first line contains a single integer TT (1T5001 \le T \le 500) - the number of test cases. Description of the test cases follows. The first line of each test case contains one integer nn (1n1051 \le n \le 10 ^ 5) - the number of heap(s). The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10 ^ 9) - the number of stone(s) of each heap. It's guaranteed that n106\sum n \le 10 ^ 6.

Output

For each test case, print a single integer - the probability of Alice winning, modulo 998244353998244353.

Sample Input

2
2
1 1
1
2

Sample Output

0
499122177

Source

2023“钉耙编程”中国大学生算法设计超级联赛(7)