#Lutece3229. 米奇妙妙程序

米奇妙妙程序

Migrated from Lutece 3229 米奇妙妙程序

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

初始一个长为 nn 的序列 {an}\{a_n\},下标从 11 开始,所有元素均为 00。且有变量 FailFail,初值为 00

现执行以下操作 mm 次:

  1. {1,2,,n}\{1,2,\dots,n\} 中等概率选取一个值,记为 pp
  2. ap=0a_p=0 ,则置 apa_p 为 1,否则:
    1. {0,1}\{0,1\} 中等概率选取一个值,记为 xx
    2. x=0x=0 ,则找到最小的 ii,满足 ai=0a_i=0i>pi>p; 若 x=1x=1 ,则找到最大的 ii,满足 ai=0a_i=0i<pi<p
    3. ii 存在,置 ai=1a_i=1; 否则,置 Fail=1Fail=1

P(Fail=0)P(Fail=0) 在模 109+710^9+7 意义下的结果。

Input

本题采用多测,第一行,一个正整数 TT ,表示数据组数

对于每组数据,一行,两个正整数 nnmm

Output

对于每组数据,一行,一个整数,表示答案。

Samples

输入数据 1

2
2 1
2 2

输出数据 1

1
750000006

Constraints

1mn1051\leq m\leq n\leq 10^51T1021\leq T \leq 10^2

Resources

2024 UESTC ICPC Training for Math