You are on page 1of 2

8/27/2021 Newton School

Newton School PL

back
Save and Run Hidden Test
Newton's Grand Contest 2021 - Groot and The Groots (Public Contest: August 2021) by 01:41:59
Run Cases
Pranav Lad

Groot and The Groots (Public Contest: August 2021)

standard input/output: 3s/256000 kB

Baby Groot is very interested in finding out what he would look like when he grows up. But Groot being Groot, he cannot see into the future. Seeing Groot sad, Stephen
Strange allows him to use the time stone. When Groot tried to see the future, he saw the multiverse, which was filled with many different Groots. He knows that every future
version of him is a labelled bipartite graph with n nodes coloured in a special way. Each edge has been coloured with one of p colours, and exactly one node of each
component has been coloured with one of k colours. He wanted to know how many distinct versions of himself can be present in the future.

Formally, a labelled bipartite graph G can be coloured as follows:

i. For each component, we choose precisely one vertex and colour it with one of k colours.

ii. For each edge of the graph, we colour it with one of p colours.

Let f(G) denote the number of such colourings of a graph G. Find the sum of f(G) over all labelled bipartite graphs G consisting of n vertices labelled from 1 to n.

Now, this number can be large, so Groot just wants its value modulo 998244353. Can you help Groot find this value?

Input
First line contains an integer T - the number of test cases.

Then T lines follow, each line containing three space-separated integers n, k and p.

Constraints:

1 ≤ T ≤ 4×104

1 ≤ n ≤ 4×104

1 ≤ k ≤ 108

1 ≤ p ≤ 108

The sum of n across all test cases does not exceed 4×104.

Output
Output T lines, the ith line containing the answer for the ith test case.

Example
Sample Input:
3
1 2 2
2 1 1
3 3 2
 
Sample Output:
2
3
243

Code Reset Python (3.8.1) Custom Input


1
1 # Your code here

STDOUT STDERR COMPILE OUTPUT MESSAGE


1

Test Cases Previous Submissions

Test case 0 Hidden test case Status Test Cases Passed

Test case 1
Help

Test case 2
https://my.newtonschool.co/playground/code/sxqvwpkphta4/ 1/2
8/27/2021 Newton School

Test case 3

Test case 4

Test case 5

Test case 6

Test case 7

Test case 8

Test case 9

Test case 10

Test case 11

Test case 12

© 2021 Incanus Technologies Pvt Ltd


For any queries, you can reach us at Follow us on
All rights reserved. (Terms) support@newtonschool.co

https://my.newtonschool.co/playground/code/sxqvwpkphta4/ 2/2

You might also like