Do you know this problem: https://atcoder.jp/contests/agc022/tasks/agc022_e? We generalize it a bit.
You got a binary string P=P_0P_1P_2P_3P_4P_5P_6P_7 of length 8.
You think a binary string X of odd length N is beautiful if it is possible to apply the following operation 2N−1 times so that the only character of the resulting string is '1' :
Note that, when P=00010111, this definition is the same as the original AGC problem.
You have a string S consisting of characters '0', '1', and '?'. You want to know the number of ways to replace the question marks with '1' or '0' so that the resulting string is beautiful, modulo 109+7.
Note that there are T tests in one input file.
Input is given from Standard Input in the following format:
T
P S
P S
⋮
P S
For each case, print the answer in a line.