#CF2240F. 猎兽 / F. Hunting the Beast

猎兽 / F. Hunting the Beast

F. Hunting the Beast

Source: Codeforces 2240F
Contest: Codeforces Round 1105 (Div. 2)
Time limit: 2 seconds
Memory limit: 256 megabytes

Statement

In Zhuji, a city in central Zhejiang Province, local folklore tells of a wild beast known as the Modeiyon. Dwelling deep in the mountains, it is said to sneak into villages at night to devour livestock and prey on lone travelers. Though many elders claim to have seen it, no photograph of the creature has ever been taken.

A brave group of mm people decides to head up the mountain to hunt the beast. The mountain's locations and trails can be modeled as a functional graph GG with nn vertices (numbered 11 to nn). A functional graph is a directed graph with nn vertices and nn edges, where every vertex has an out-degree of exactly 11. Additionally, it is known that the mountain's trails do not ever form self-loops.

The group will choose exactly mm distinct vertices to form their initial starting set SS. A starting set SS is defined as successful if every vertex uu in the graph is reachable from at least one vertex vSv \in S (a vertex is always reachable from itself).

There are (nm)\binom{n}{m} possible ways to choose the starting set of size mm. They define the value of a graph GG as the number of successful starting sets it has.

However, the exact layout of the mountain's trails is unknown. If the destination of the single outgoing edge from each vertex is chosen arbitrarily from the remaining n1n-1 vertices (excluding the vertex itself), there are exactly (n1)n(n-1)^n possible functional graphs. Given nn and mm, your task is to calculate the sum of the values of all (n1)n(n-1)^n possible functional graphs. Since the answer can be very large, print it modulo 998244353998\,244\,353.

Input

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

The only line of each test case contains two integers n,mn,m (1mn1061\le m \le n\le 10^6) — the number of vertices in the graph and the number of starting vertices.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

Output

For each test case, output a single integer — the sum of the values of all (n1)n(n-1)^n possible functional graphs, modulo 998244353998\,244\,353.

Note

In the first test case, there is exactly (21)2=1(2-1)^2=1 valid functional graph: 121 \to 2 and 212 \to 1. Both starting sets of size 11 ({1}\{1\} and {2}\{2\}) can reach all vertices. Thus, the total value is 22.

In the second test case, there are (31)3=8(3-1)^3=8 valid functional graphs. They can be categorized as follows:

  • 22 graphs form a single cycle of length 33 (e.g., 12311 \to 2 \to 3 \to 1). Starting at any of the 33 vertices can reach all vertices. This contributes 23=62 \cdot 3 = 6 to the total value.
  • 66 graphs consist of a 22-cycle and a single leaf pointing to it (e.g., 121 \leftrightarrow 2 and 313 \to 1). To reach all vertices, the starting set must be exactly the leaf vertex. This contributes 61=66 \cdot 1 = 6 to the total value.

The total sum of values is 6+6=126 + 6 = 12. In the third test case, the 88 possible graphs are the same, but we choose subsets of size m=2m=2:

  • For the 22 cycle graphs, any subset of size 22 is successful. This contributes 2(32)=62 \cdot \binom{3}{2} = 6.
  • For the 66 leaf graphs, the subset must contain the leaf vertex. There are exactly (21)=2\binom{2}{1}=2 such subsets for each graph. This contributes 62=126 \cdot 2 = 12.

The total sum of values is 6+12=186 + 12 = 18.

Examples

5
2 1
3 1
3 2
4 2
8 3
2
12
18
216
20415360