시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB666100.000%

문제

Solve the problem below for $T$ test cases.

You are given two integers $M$ and $D$. You are interested in a rooted weighted tree with the following conditions.

  • Each edge has a weight of a positive integer.
  • For each vertex $v$ of the tree, there exists no set of $v$'s children of size strictly greater than $M$ such that all the edges connecting $v$ and this set of children all have the same weight.
  • The diameter of the tree is not greater than $D$. The diameter of a tree is the maximum distance between any two vertices.

Find the maximum number of vertices of such a tree. As the number of vertices can be very large, find the vertex count modulo $998244353$.

입력

The first line contains an integer $T$ ($1 \leq T \leq 100$), the number of test cases. Each of the next $T$ lines contains two integers $M$ and $D$ ($1 \leq M, D \leq 10^9$) representing a case you have to solve.

출력

For each of the $T$ test cases, output a single line containing the maximum number of vertices modulo $998244353$.

예제 입력 1

3
2 4
165 1
20 20

예제 출력 1

12
2
891869870

Explanation of Sample 1: The following illustrates, for the first case, a rooted tree with the maximum number of vertices.