logo AlgoBeat OnlineJudge
登录 注册

#212202. [NWRRC2024] Capybara Cozy Carnival

内存限制:1024 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Chilling capybaras celebrate Capybara Cozy Carnival. Chairman capybara cuts convex cake. Cake contains colorful corners. Countless colors comprise choices. Creating continuous crossing-free corner-to-corner cuts, chairman cuts cake chunks, catering comrades. Curiously, consecutive cake chunks corners contain contrasting colors.

Calculate cake corners color combinations, considering cuts conditions.

In other words, you are given a cake in the shape of a regular -sided polygon and non-intersecting diagonal cuts, which divide it into slices.

Calculate the number of ways to color each corner of the original cake with one of the colors, such that no two neighboring corners of the resulting slices have the same color. Two corners are considered neighboring if they are either consecutive in the original cake, or they are the endpoints of the same cut. It is not necessary to use all the colors. As the number of ways might be large, find it modulo .

输入格式

Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.

The first line of each test case contains three integers , , and , denoting the number of cake corners, the number of cuts, and the number of available colors (; ; ).

The -th of the following lines contains two integers and , denoting the corners connected by the -th cut (). No two cuts may coincide or intersect except at the ends of the cuts. All cuts are straight, going strictly inside the cake.

It is guaranteed that the sum of over all test cases does not exceed .

输出格式

For each test case, print the number of ways to color the cake corners such that no two neighboring corners have the same color, modulo . Remember that you don't have to use all the colors.

样例

样例输入 1

4
4 1 3
1 3
5 0 2
9 4 3
1 3
1 6
4 6
6 8
3 0 1001

样例输出 1

6
0
54
1754647