F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Many Topological Problems

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 195    Accepted Submission(s): 159


Problem Description
Once you created the following problem:

**Topological Problem**

You are given a labeled rooted tree with $n$ vertices and an integer $k$. We call a permutation $a$ of length $n$ good if $a_i>a_{par_i}$ and $a_i\le a_{par_i}+k$ for each $i$ with a parent $par_i$.

Find the number of good permutations.

Now, thinking this problem is too easy, you create the following problem:

**Many Topological Problems**

You are given two integers $n,k$. For all different labeled rooted trees $T$ with $n$ vertices, find the sum of the answer to the *Topological Problem* of $T$, modulo $10^9+7$.

Please solve **Many Topological Problems**.

Two labeled rooted trees are considered different, if and only if their roots differ, or one edge exists in one tree but not in the other.
 

Input
The first line contains a single integer $T$ ($1\le T\le 10$), denoting the number of test cases.

For each test case, the only line contains two integers $n,k$ ($1\le k\le n\le 10^6$).
 

Output
For each test case, output one line with an integer denoting the answer.
 

Sample Input
3 2 2 5 1 114514 1919
 

Sample Output
2 120 354463397
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 21:32:49, Gzip enabled