Capybara Cozy Carnival

시간 제한4초메모리 제한2048 MB

요약
다각형의 꼭짓점을 k가지 색으로 칠하되, 서로 교차하지 않는 대각선의 양 끝점도 이웃으로 취급하여 인접한 두 꼭짓점이 다른 색이 되도록 칠하는 경우의 수를 998244353으로 나눈 나머지를 구한다.
난이도

보통10점 중 7점

유형
조합론, 수학, 그래프, 동적 계획법
정답자
아직 제출이 없습니다

문제

Chilling capybaras celebrate Capybara Cozy Carnival. Chairman capybara cuts convex cake. Cake contains nn colorful corners. Countless colors comprise kk choices. Creating mm continuous crossing-free corner-to-corner cuts, chairman cuts cake chunks, catering m+1m + 1 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 nn-sided polygon and mm non-intersecting diagonal cuts, which divide it into m+1m + 1 slices.

Calculate the number of ways to color each corner of the original cake with one of the kk 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 998,244,353998\\,244\\,353.

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers nn, mm, and kk, denoting the number of cake corners, the number of cuts, and the number of available colors (3≤n≤1093 \le n \le 10^9; 0≤m≤2⋅1050 \le m \le 2\cdot 10^5; 2≤k≤1062 \le k \le 10^6).

The ii-th of the following mm lines contains two integers u_iu\_i and v_iv\_i, denoting the corners connected by the ii-th cut (1≤u_i<v_i≤n1 \le u\_i < v\_i \le n). 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 mm over all test cases does not exceed 2⋅1052\cdot 10^5.

출력

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 998,244,353998\\,244\\,353. Remember that you don't have to use all the colors.

힌트

In the first test case, corner 11 has one of 33 colors. Corner 22 has one of the remaining 22 colors. Corner 33 has the remaining color, and corner 44 has the same color as corner 22. Thus, there are 66 ways in total.

In the second test case, we have an odd number of corners and two colors, and every pair of consecutive corners must have different colors; that is impossible.

예제1

  1. 예제 1

    입력
    4
    4 1 3
    1 3
    5 0 2
    9 4 3
    1 3
    1 6
    4 6
    6 8
    3 0 1001
    
    예상 출력
    6
    0
    54
    1754647