Gambling Monster
题号:NC224163
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Tukuai, the gambling monster, is playing a gambling game with a machine consisting of a turntable and a display screen.

The turntable is divided into  parts, numbered . The area of the -th part is , which means the probability of getting integer  is , if the player turn the turntable once.

An integer  will be displayed on the screen during the game. At the beginning, . The goal of the game is to make  to get the prize. The player can do the following operation any times before  (If , the game ends immediately):

Pay one coin and turn the turntable once, then get an integer . The player can choose to make , or keep  unchanged, where  is bitwise-xor operation.

As a gambling monster, Tukuai is greedy, so he will make  once , or keep  unchanged if .

What is the expected number of coins that need to be paid by Tukuai to get the prize? Find the answer modulo . Or formally, let . It can be shown that the answer can be expressed as an irreducible fraction , where . Find the value .

输入描述:

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

The first line of each test case contains an integer  ( and  is a power of ).

The second line of each test case contains  integers .

It is guaranteed that the sum of  over all test cases does not exceed .

输出描述:

For each test case, output the answer modulo , in a single line.

示例1

输入

复制
2
4
1 2 2 1
8
1 2 3 4 5 6 7 8

输出

复制
200000005
119223647

说明

The answer of the first test case of the example can be expressed as  in irreducible fraction.

备注: