Under construction

Still being built. Things may change

Cactus

Time limit8sMemory limit512 MB

Summary
Count the proper k-colorings of a cactus graph, where each vertex lies on at most one cycle, modulo 10^9+7.
Level

Medium7 of 10

Topics
Graph, DFS, Combinatorics
Solved
No attempts yet

Problem

Let me be upfront about this: things are not going well. What was supposed to be a relaxing evening with friends took a turn for the worse when you were assaulted by a walking advertisement of cheap cologne, and your Priceless Argentinian Cactus, the only thing you hold dear, was thrown out of the window.

Right after the deed, or as soon as was physically possible, you ran down the stairs to assess the losses. And there it was, your priceless cactus, alive! It had a few scratches, but it was alive. How did this happen? Did it land on something soft? Overwhelmed with joy, you decide not to look for answers. Did I say things are not going well? Scratch that. Everything is great, and it is time to celebrate! The guest of honor, of course, is your green stinging friend.

For those less acquainted with botany, a refresher: a cactus is a connected graph in which each vertex lies on at most one cycle. To add to the festive mood, you decide to color every vertex of your cactus with one of kk colors. You want as much freedom as possible, but you must follow the golden rule of cactus coloring: no two adjacent vertices may have the same color.

One coloring seems not enough, so once the colors fade, you will recolor the cactus again and again, using a different coloring each time. But how long can you keep this going? Given the description of your cactus and the number kk, count the number of correct kk-colorings of the cactus' vertices. The answer may be very large, so it is enough to compute it modulo 109+710^9 + 7.

Input

The first line contains the number of test cases zz (1≤z≤500001 \leq z \leq 50000). The test cases follow.

The first line of each test case contains three integers nn, mm, and kk (1≤n≤3000001 \leq n \leq 300000, 0≤m≤4000000 \leq m \leq 400000, 2≤k≤1092 \leq k \leq 10^9), where nn is the number of vertices, mm is the number of edges, and kk is the number of colors.

The next mm lines each contain two integers uiu_i and viv_i (1≤ui≠vi≤n1 \leq u_i \neq v_i \leq n), describing an edge of the cactus. The given graph is guaranteed to be a cactus, and every pair of vertices is connected by at most one edge.

The total number of vertices over all test cases does not exceed 3⋅1063 \cdot 10^6, and the total number of edges does not exceed 4⋅1064 \cdot 10^6.

Output

For each test case, output a single integer: the number of proper colorings of the cactus' vertices with kk colors, modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    2
    2 1 100
    1 2
    6 7 3
    1 2
    2 3
    3 1
    4 5
    5 6
    6 4
    1 4
    
    Expected output
    9900
    24