QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#3686. Mahjong

统计

Mahjong is a popular game in Asia. Mahjong tiles are as follows, with at most 4 of each type:

We denote these tiles as 1m, 2m, 3m, ..., 9m.

We denote these tiles as 1s, 2s, 3s, ..., 9s.

We denote these tiles as 1p, 2p, 3p, ..., 9p.

We denote these honor tiles as 1c, 2c, 3c, ..., 7c.

A standard winning state is a set of $14$ tiles containing one pair of identical tiles (e.g., 2s,2s or 4c,4c) and four sets of tiles, where each set contains $3$ tiles, either three identical tiles (e.g., 6m,6m,6m or 2c,2c,2c) or three consecutive tiles of the same suit (e.g., 4m,5m,6m or 1p,2p,3p).

There are two special winning states. The first is "Seven Pairs," which consists of $7$ groups, each being a pair of identical tiles, where no two groups can be the same (e.g., 1m,1m,2m,2m,4m,4m,5m,5m,6c,6c,1s,1s is a valid configuration, while 1m,1m,2m,2m,4m,4m,5m,5m,2m,2m,1s,1s is not, because one pair is repeated).

The second is "Thirteen Orphans," which consists of one of each of 1m,9m,1s,9s,1p,9p,1c,2c,3c,4c,5c,6c,7c, plus one additional tile from the aforementioned $13$ types (e.g., 1m,9m,1s,9s,1p,9p,1c,2c,3c,4c,5c,6c,7c,9p is a winning state).

Given $N$ tiles, where the quantity of each type does not exceed $4$, calculate the probability of a "Heavenly Hand" (i.e., drawing $14$ tiles such that they form a winning state).

Input

There are multiple test cases. For each test case, the first line contains an integer $T$, representing the total number of test cases. For each test case, the first line contains an integer $N$, and the next line contains $N$ strings representing the $N$ tiles. See the examples for details.

Output

For each test case, output a single line representing the probability of a Heavenly Hand as an irreducible fraction. The numerator and denominator should be separated by a /.

Examples

Input 1

4
14
1s 2s 3s 2c 2c 2c 2p 3p 4p 5m 6m 7m 1p 1p
14
1s 2s 3s 2c 2c 2c 2p 3p 4p 5m 6m 7m 1p 2p
25
1m 1m 9m 9m 1s 1s 9s 9s 1p 1p 9p 9p 1c 1c 2c 2c 3c 3c 4c 4c 5c 5c 6c 6c 7c
27
1m 1m 1m 2m 2m 2m 3m 3m 3m 4m 4m 4m 5m 5m 5m 6m 6m 6m 7m 7m 7m 8m 8m 8m 9m 9m 9m

Output 1

1/1
0/1
1057/185725
44171/371450

Constraints

For $40\%$ of the data, $N \leq 25$.

For $100\%$ of the data, the number of test cases $T \leq 10$, and $14 \leq N \leq 136$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.