Under construction

Still being built. Things may change

Illuminated Lights II

Interview

Time limit1sMemory limit1024 MB

Summary
Count the subsets of lights, each pointing L or R, that illuminate every light in the row, modulo 1e9+7.
Level

Medium5 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Statement

There are nn lights in a row, all initially deactivated. Some lights, when activated, illuminate themselves and all lights to their left. The others, when activated, illuminate themselves and all lights to their right.

The image below shows the result of activating only the fourth light in the first sample case. Lights 1 through 4 are illuminated, and no others are.

You already know the minimum number of lights that must be activated to illuminate everything, from this earlier problem. Now you want to count the good subsets.

A subset SS of the lights is good if activating only the lights in SS illuminates every light in the row. Count the good subsets. Since the count can be large, print it modulo 109+710^9+7.

Input

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4), the number of test cases. Each test case starts with a line containing a single integer nn (1≤n≤2⋅1051 \le n \le 2\cdot 10^5), the number of lights. The next line contains a string ss of length nn made of the characters L and R. L means the light points left, and R means it points right.

The sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

Output

For each test case, print the number of good subsets modulo 109+710^9+7 on its own line.

Hint

For the second and fourth test cases, the only way to illuminate everything is to activate every light. So for these cases, the only good subset is the set of all lights.

For the third test case, activating either light illuminates everything. So the sets {1}\{1\}, {2}\{2\}, and {1,2}\{1, 2\} are good.

Examples1

  1. Example 1

    Input
    7
    6
    LRRLRL
    1
    L
    2
    RL
    2
    LR
    5
    RRRRL
    10
    LRLRLRLRLR
    31
    LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
    
    Expected output
    50
    1
    3
    1
    24
    912
    73741817