问题 D: Data Generation

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Yoshinow2001 is making data for his problem. He wants to generate a random permutation of {0,,n1} , so he used the following algorithm:




Here, we can assume that the function rand()modn is able to generate integer randomly in the set {0,,n1} with equal probability.

Now Yoshinow2001 is concerned that this algorithm is not random enough ------ after all, if you want to randomize a permutation, the expected number of elements for ai=i should be n1. So he wants to ask what the mathematical expectation of the final ans is.

输入格式

The first line of input is a positive integer T(1T10^5) representing the number of data cases.

For each cases consists of a single line of two integers n,m, separated by a space. Where 1n10^18,0m10^18, ensure that n is not a multiple of 998 244 353998 244 353.

输出格式

For each cases, output a line with a positive integer representing the answer mod998 244 353mod998 244 353.

输入样例 复制

3
1 0
1 1
2 1

输出样例 复制

0
0
1