문제
Consider a network of
The connections between the nodes in this network can be described by a list of directed edges each of the form
The description of a "routing scheme" consists of a set of
to a receiver
such that the directed edges
Count the number of distinct routing schemes such that every directed edge is traversed exactly once. Since the answer may be very large, report it modulo
Each input contains
over all test cases does not exceed
입력
The first line of the input contains
The first line of each test case contains the integers
The second line of each test case contains a string of length
The next
Consecutive test cases are separated by newlines for readability.
출력
For each test case, the number of routing schemes such that every edge is traversed exactly once, modulo
예제1
2
8 0
SS....RR
00100000
00100000
00011000
00000100
00000100
00000011
00000000
00000000
13 0
SSS.RRRSS.RR.
0001000000000
0001000000000
0001000000000
0000111000000
0000000000000
0000000000000
0000000000000
0000000001000
0000000001000
0000000000110
0000000000000
0000000000000
0000000000000
4
12

예제2
For the first test case, the edges are
There are three possible routing schemes:
For the second test case, the edges are
.
There is only one possible routing scheme:
.
예제3
5
3 2
RS.
010
101
100
4 2
.R.S
0100
0010
1000
0100
4 2
.SR.
0000
0011
0100
0010
5 2
.SSRR
01000
10101
01010
00000
00000
6 2
SS..RR
001010
000010
000010
000010
100101
000000
2
1
2
6
24
Some additional small test cases.