시간 제한메모리 제한제출정답맞은 사람정답 비율
5 초 512 MB0000.000%

## 문제

Sherlock and Watson have already been introduced to sorting in their computer programming course. Now, Watson has always been curious about parallel computing and wants to sort a permutation of the integers 1 through N by breaking it into chunks, sorting the chunks individually, and then concatenating them.

For a permutation p1, p2, ..., pN, a chunk is a contiguous subarray of the permutation: i.e., a sequence of elements pi, pi + 1, ..., pj, for the elements at indexes i and j such that 1 ≤ i ≤ j ≤ N.

Watson wants to partition his permutation into an ordered list of one or more chunks, without changing the order that the elements are in, in such a way that each element of the permutation is in exactly one chunk, and all elements in a chunk are smaller than all elements in any later chunk.
For example, for the permutation [2, 1, 3, 5, 4], these are the only four legal ways for Watson to break it into chunks: [[2, 1, 3], [5, 4]] or [[2, 1], [3, 5, 4]] or [[2, 1], , [5, 4]] or [[2, 1, 3, 5, 4]]. Watson is happiest when there are as many chunks as possible; we denote the maximum number of chunks for a permutation p as f(p). In this example, the maximum number of chunks is 3.

Watson wants to consider all permutations p of the numbers 1 through N, and find the sum of squares of f(p). Watson knows Sherlock might come in handy and comes to him for help, but Sherlock is as clueless as Watson and asks you for help. As the sum of squares can be large, please find it modulo M.

## 입력

The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of one line with two integers N and M.

Limits

• 1 ≤ M ≤ 109.
• 1 ≤ T ≤ 100.
• 1 ≤ N ≤ 100.

## 출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the sum of squares of f(p) for all permutations p of size N, modulo M.

## 예제 입력 1

3
1 2
2 4
3 7


## 예제 출력 1

Case #1: 1
Case #2: 1
Case #3: 6



## 힌트

In Case 1, there is only one permutation. f() * f() % 2 = 1.

In Case 2, there are two permutations.
f([1, 2]) = 2.
f([2, 1]) = 1.
(22 + 12) % 4 = 1.

In Case 3, there are six permutations.
f([1, 2, 3]) = 3.
f([1, 3, 2]) = 2.
f([2, 1, 3]) = 2.
f([2, 3, 1]) = 1.
f([3, 1, 2]) = 1.
f([3, 2, 1]) = 1.
(32 + 22 + 22 + 12 + 12 + 12) % 7 = 6.

## 채점 및 기타 정보

• 예제는 채점하지 않는다.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8838023,"math_prob":0.9952401,"size":2294,"snap":"2021-43-2021-49","text_gpt3_token_len":756,"char_repetition_ratio":0.13537118,"word_repetition_ratio":0.008368201,"special_character_ratio":0.35789016,"punctuation_ratio":0.18499127,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9944084,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-19T04:42:48Z\",\"WARC-Record-ID\":\"<urn:uuid:6c21de17-98be-4d9a-8680-3570fc3e2a4e>\",\"Content-Length\":\"28339\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:25081d62-a757-4de5-af17-f7219df25934>\",\"WARC-Concurrent-To\":\"<urn:uuid:39e98fdd-84c6-4364-a8d8-f3e66545fad1>\",\"WARC-IP-Address\":\"52.69.177.81\",\"WARC-Target-URI\":\"https://www.acmicpc.net/problem/14320\",\"WARC-Payload-Digest\":\"sha1:G3IKH4QYMTHREKOPH54YVQN6SMLFBR3Q\",\"WARC-Block-Digest\":\"sha1:JJUXMC2W27KCMT7E5M6RI6C5J3BXBWQR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585242.44_warc_CC-MAIN-20211019043325-20211019073325-00319.warc.gz\"}"}