Luis was sleeping. He suddenly woke up with three positive integers , and . He told his younger brother Hansi these three integers. Hansi is too young and weird. He wrote all possible distinct arrays of length such that only integers from to occurs in it and none of their frequency is more than . Note that, any element in an array will be in , but not all integers from may be present in an array.
Luis defines score of an array as the maximum frequency of its elements in it. Can you tell the sum of score of all arrays that Hansi wrote? Print it modulo .
Frequency of an element in an array is defined as the number of times the element occurs in that array.
First line of the input will have two space-separated integers , number of testcases and integer . will be prime.
Each of the next lines will have three space-separated integers , and describing the testcase.
For each testcase, output an integer , which is the sum of score of all arrays that Hansi wrote, modulo .
Input | Output |
---|---|
3 998244353 2 2 1 2 2 2 2 1 1 | 2 6 0 |
In first test, Hansi will write and . Score of both arrays is . So, the output will be .
In second test, Hansi will write , , and . Score of the arrays are , , , respectively. So, the sum will be .
In third test, Hansi will not be able to write any array. So, the output will be .