Automaton

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Given nn and kk, calculate the expected number of vertices in the suffix automaton of a random string of length nn over alphabet of size kk. If rr is the answer, output rknr\cdot k^n modulo 109+710^9 + 7.

입력

The first line contains the number of tests TT. Each of the next TT lines contains integers nn and kk (1kn401 \le k \le n \le 40). All tests in the input are different.

출력

Output TT lines with answers for tests.

힌트

Let S(s)S(s) be the set of all substrings of ss. Suffix automaton of a string ss is the smallest directed acyclic graph with a specified vertex v_0v\_0 and an assignment l(e)l(e) of characters to all edges of GG that satisfies the following property: S(s)=l(e_1)l(e_k)(e_1,,e_k) — a path starting at v_0S(s) = \\{l(e\_1)\ldots l(e\_k) \mid (e\_1, \ldots, e\_k)\text{ --- a path starting at }v\_0\\}.