La omul care mi-i drag

Time limit: 1.5s Memory limit: 1024MB Input: Output:

La omul care mi-i drag
Treabă n-am dar cale-mi fac
Iar la cel ce mi-i urât
Treabă am dar nu mă duc

You are given an n×nn \times n grid of nonzero digits. The value of the cc-th cell from the rr-th row is known to be arca_{rc}. Note that 1arc91 \le a_{rc} \leq 9.

A DR-path is a sequence of cells (r1,c1),(r2,c2),,(rk,ck)(r_1,c_1), (r_2, c_2), \ldots, (r_k, c_k) which satisfies the following constraints:

  • (r1,c1)=(1,1)(r_1,c_1)=(1,1)
  • (rk,ck)=(n,n)(r_k,c_k)=(n,n)
  • For all 1i<k1 \le i < k, (ri+1,ci+1)=(ri+1,ci)(r_{i+1},c_{i+1}) = (r_i+1,c_i) or (ri+1,ci+1)=(ri,ci+1)(r_{i+1},c_{i+1}) = (r_i,c_i+1).

The value of a DR-path (r1,c1),(r2,c2),,(rk,ck)(r_1,c_1), (r_2, c_2), \ldots, (r_k, c_k) is equal to:

φ(ar1c1ar2c2arkck)\varphi(a_{r_1c_1} \cdot a_{r_2c_2} \cdot \ldots \cdot a_{r_kc_k})

where φ(x)\varphi(x) denotes the number of integers 1yx1 \le y \le x for which gcd(x,y)=1\gcd(x,y)=1. Note that, based on this definition, φ(1)=1\varphi(1)=1.

Task

Find any DR-path (r1,c1),(r2,c2),,(rk,ck)(r_1,c_1), (r_2, c_2), \ldots, (r_k, c_k) with the maximum value. For that DR-path you will have to print a string ss of length k1k-1 which is defined in the following way:

si={D,if (ri+1,ci+1)=(ri+1,ci)R,otherwises_i=\begin{cases}\text{D}, &\text{if } (r_{i+1},c_{i+1}) = (r_i+1,c_i) \\ \text{R}, & \text{otherwise} \end{cases}

Input data

Each test contains multiple test cases. The first line of input contains a single integer tt — the number of test cases.

The first line of each test case contains a single integer nn — the size of the grid.

Each of the next nn lines of input contains a string of nn digits. The ii-th of these lines will contain the string ai1ai2ain\overline{a_{i1} a_{i2} \ldots a_{in}}.

Output data

For each test case, print a string of D's and R's corresponding to any DR-path with the maximum value.

Constraints and clarifications

  • 1t1051 \leq t \leq 10^5
  • 2n1 0002 \leq n \leq 1\ 000
  • 1aij91 \leq a_{ij} \leq 9
  • The sum of n2n^2 across all test cases does not exceed 10610^6.

Example

stdin

4
3
188
956
671
2
12
21
2
69
76
4
9667
7181
5934
7522

stdout

DRDR
DR
RD
RRDDRD

In the first test case, the DR-path (1,1),(2,1),(2,2),(3,2),(3,3)(1,1),(2,1),(2,2),(3,2),(3,3) has a value of φ(19571)=144\varphi(1 \cdot 9 \cdot 5 \cdot 7 \cdot 1)=144. We can show that no other DR-paths have a higher value.

In the second test case, all DR-paths have a value of φ(2)=1\varphi(2)=1.

In the third test case, the DR-path (1,1),(1,2),(2,2)(1,1),(1,2),(2,2) has a value of φ(696)=108\varphi(6 \cdot 9 \cdot 6)=108. We can show that no other DR-paths have a higher value.

Log in or sign up to be able to send submissions!