#P10968. 扑克牌

扑克牌

Problem Description

A standard deck of playing cards without jokers consists of 5252 cards, divided into 44 suits: hearts, spades, clubs, and diamonds. Each suit has 1313 cards with different ranks. Now you are given some cards from these 5252 cards. Please compute the number of ways to arrange them into a line such that any two adjacent cards have different ranks.

A card is represented as XY, where X is the rank, one of 2,3,4,5,6,7,8,9,T,J,Q,K,A. Y is the suit, one of S,H,D,C. For example, 2S, 2H, TD, etc.

Input Format

The first line contains an integer TT, the number of test cases.

Each test case occupies one line. The line first contains an integer NN, meaning the number of given cards, followed by NN space-separated strings. Each string has length 22 and represents one card. All cards in the same test case are distinct.

Output Format

For each test case, output one line in the form Case #X: Y. XX is the test case number starting from 11. YY is the number of valid arrangements. Since the answer may be very large, output the value modulo 2642^{64}.

5
1 TC
2 TC TS
5 2C AD AC JC JH
4 AC KC QC JC
6 AC AD AS JC JD KD
Case #1: 1 
Case #2: 0 
Case #3: 48 
Case #4: 24 
Case #5: 120

Hint

Translated by ChatGPT 5