Under construction

Still being built. Things may change

Anti-hash Test

Time limit1sMemory limit256 MB

Summary
Count occurrences of u in the popcount-parity string s(n) of length 2^n, and how many strings v share that occurrence count.
Level

Hard9 of 10

Topics
String matching, Recursion, Math
Solved
No attempts yet

Problem

It is well known that the following string s(n)=s0s1…s2n−1s(n) = s_0 s_1 \ldots s_{2^n-1} can challenge almost every solution that uses polynomial hashes modulo 2642^{64}:

si={a,popcount(i) mod 2=0b,popcount(i) mod 2=1s_i = \begin{cases} \text{a}, & \mathrm{popcount}(i) \bmod 2 = 0 \\ \text{b}, & \mathrm{popcount}(i) \bmod 2 = 1 \end{cases}

where popcount(i)\mathrm{popcount}(i) is the number of ones in the binary representation of ii.

Given a string uu and an integer nn, find the number of occurrences of uu in s(n)s(n) and the number of distinct strings vv that have the same number of occurrences in s(n)s(n). Both numbers can be very large, so print them modulo 109+710^9 + 7.

Input

There are multiple test cases. The first line contains an integer TT, the number of test cases. Each test case has two lines.

The first line contains an integer nn (1≤n≤10181 \le n \le 10^{18}).

The second line contains a string uu (1≤∣u∣≤min⁡(106,2n)1 \le |u| \le \min(10^6, 2^n)) consisting only of the letters a and b.

The sum of ∣u∣|u| over all test cases does not exceed 10610^6.

Output

For each test case, if uu does not appear in s(n)s(n), print −1-1. Otherwise, print two integers: the number of occurrences of uu in s(n)s(n) modulo 109+710^9 + 7, and the number of distinct strings vv with the same number of occurrences in s(n)s(n) modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    4
    10
    a
    10
    abba
    5
    abbabaabbaababbabaababbaabbabaab
    20
    ababab
    
    Expected output
    512 2
    171 4
    1 344
    -1