Balanced Binary String

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

Chiaki has a string ss of length nn, consisting of '0', '1' and '?'.

A circular substring s(i,l)s(i,l) of s=s_1s_2s_ns=s\_1s\_2 \dots s\_{n} is string {s_is_i+1s_i+l1i+l1n s_is_i+1s_ns_1s_2s_i+l1ni+l1>n\begin{cases} s\_i s\_{i+1} \dots s\_{i + l - 1} & i + l - 1 \le n \\\ s\_is\_{i+1} \dots s\_n s\_1 s\_2 \dots s\_{i + l - 1 - n} & i + l - 1 > n \end{cases}.

A binary string ss of length nn is balanced if for every two circular substrings s(i,l)s(i,l) and s(j,l)s(j,l) (1i,j,ln1 \le i, j, l \le n), the number of 11's in s(i,l)s(i,l) and s(j,l)s(j,l) differ at most by one. For example, 101101 and 1101011011010110 are balanced, while 11001100 and 10101101101010110110 are not balanced.

Chiaki would like to know the number of ways to replace every '?' to '0' or '1' in her string to make it balanced. Since this number may be very large, you are only asked to calculate it modulo 109+710^9+7.

입력

There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains a nonempty string ss (1s10241 \le |s| \le 1024) consisting of '0', '1' and '?'.

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

출력

For each test case, output an integer denoting the number of ways.