Under construction

Still being built. Things may change

Brain fold (Easy)

Time limit2sMemory limit1024 MB

Summary
Given a sequence of folds and one cut line on the folded paper, find how many pieces the sheet has after unfolding, modulo 1e9+7.
Level

Easy3 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Shandyna loves nerd sniping. (Relevant xkcd) Don't worry, she only does it in safe environments.

Last time she got five of them at once. When I saw them, they were still sitting around, trying to imagine a folded sheet of paper.

You have a rectangular piece of paper. You fold it in half several times. For each fold, you pick up one side and place it over the opposite side. There are four sides to pick, so there are four ways to perform each fold. (Two of the folds are horizontal and two are vertical.)

Once you finish the last fold, you pick a straight line and cut along it, through all layers of the folded paper. How many pieces of paper will you have at the end?

Input

The first line of the input contains an integer t=100t = 100, the number of test cases. Each test case is preceded by a blank line.

Each test case consists of three lines.

The first line contains an integer nn (1≤n≤1051 \le n \le 10^5), the number of folds.

The second line consists of nn characters, the folds in the order they are applied: T, B, L, and R mean picking up the top, bottom, left, and right side, respectively. So T is the fold that places the top side over the bottom side.

The last line describes the cut. The cut never passes through a corner of the folded paper. The exact points where the cut meets the sides do not change the number of pieces, so the cut is given only by the labels of the two sides it intersects. For example, TR is a cut that intersects the top and right sides of the folded paper.

Each cut is either horizontal or vertical. In other words, the two letters are either T and B, or L and R.

Output

For each test case, output one line containing xx modulo 109+710^9 + 7, where xx is the number of paper pieces left after cutting.

Examples1

  1. Example 1

    Input
    1
    
    2
    LB
    TB
    
    Expected output
    3