Rikka with Shortest Path
题号:NC17697
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Random Graph is an important model in CS, and Shortest Path is a basic topic in graph theory. This problem is a simple combination of them.

Rikka wants to generate an undirected graph with n vertices. It it clearly that there are possible edges. For each edge, Rikka tosses a special coin which has the probability of to be the head side and probability of to be the tail side. If the result is the head side, Rikka adds this edge to the graph. Otherwise, she does nothing.

As a result, Rikka gets an undirected graph G. And then she chooses a vertex from all n vertices randomly with equal probability and calculates the length of the shortest path from the chosen vertex to n(the length of each edge is 1.) If the chosen vertex can not reach n, Rikka will set the answer to 109.

Anyway, at last Rikka will get an integer w, it may be 109, or may represent the length of some path in G. Now, Rikka wants you to calculate the expected value of . It is easy to find that the answer must be an integer.

输入描述:

The first line contains a single integer t(1 ≤ t ≤ 5), the number of the testcases.

For each testcase, the first line contains two integers n,p(1 ≤ n ≤ 400, 0 ≤ p ≤ 106).

输出描述:

For each testcase, output a single line with a single integer, the answer modulo 998244353.
示例1

输入

复制
5
2 1000000
2 0
4 12345
10 12345
100 12345

输出

复制
276262510
466613154
86698890
508893397
860797923