Under construction

Still being built. Things may change

Game of the Retired

Time limit1sMemory limit1024 MB

Summary
Given K grid boards fenced by two non-touching R/D paths, decide who wins the token game where Jeyeon moves right and Deokin moves down.
Level

Hard9 of 10

Topics
Game theory, String, Math
Solved
No attempts yet

Problem

Having successfully retired from competitive programming, Jeyeon and Deokin made a new board game to ease the emptiness they felt. The game consists of KK boards and KK tokens. Board ii (i=1,⋯ ,Ki=1,\cdots,K) is a grid with NiN_i rows and MiM_i columns. Before the game starts, the players build a fence along the boundary of each board.

The fence is built along the edges of the grid. Consider paths of length Ni+MiN_i + M_i from the top-left corner to the bottom-right corner that move only right (R) or down (D) by one unit at a time. Choose two such paths that meet only at their starting and ending points, and build the fence along them. This is called a good fence layout.

(a)(b)(c)

Figure K.1: Good and bad fence layouts

For example, take Ni=5N_i = 5 and Mi=4M_i = 4. In (a), the two paths RRDRDDDRD and DDRRDDDRR meet only at the start and end points, so this is a good layout. In (b), the chosen paths RDRDRDRDD and DDRRDDDRR meet at a point other than the start and end, so it is not a good layout. In (c), one of the paths does not move only right or down, so it is not a good layout either.

The game begins with each board fenced by a good layout and a token placed on the top-left cell of each board. Jeyeon moves first, and the players alternate turns. On her turn, Jeyeon picks one of the KK tokens and moves it one cell to the right. On his turn, Deokin picks one of the KK tokens and moves it one cell down. A token cannot be moved across a fence. A player who has no legal move on their turn loses.

This game has no element of luck, so if both players play their best, the winner is known before the game starts. Neither of them wants to solve another problem, so you must tell them who wins.

Input

The first line contains an integer KK (1≤K1 \leq K). Then, for each board i=1,⋯ ,Ki = 1, \cdots, K, three lines follow. The first line contains NiN_i and MiM_i. The next two lines each give one of the two fence paths as a string of length Ni+MiN_i + M_i. Each string consists only of R and D, and together the two strings form a good fence layout. (1≤Ni1 \leq N_i, 1≤Mi1 \leq M_i, ∑i=1K(Ni+Mi)≤500 000\sum_{i=1}^{K} \left(N_i+M_i\right) \leq 500\,000)

Output

Print First if Jeyeon wins when both players play optimally, or Second if Deokin wins.

Hint

Figure K.2: See Sample 1

The initial boards of Sample 1 are shown above. If Jeyeon moves the token on the second board to the right on her first turn, Deokin has no legal move left, so Jeyeon wins.

Examples2

  1. Example 1

    Input
    2
    3 2
    RRDDD
    DRDDR
    1 2
    DRR
    RRD
    
    Expected output
    First
    
  2. Example 2

    Input
    2
    2 2
    DRDR
    RRDD
    4 5
    RDRDDRRRD
    DDDRDRRRR
    
    Expected output
    Second