import sys import math def comb(x,y): return 0 def hcomb(x,y): if x == 0: return y == 0 return comb(x+y-1,y) T=input() mo=1000000007 for i in range(T): C,P=map(int,raw_input().strip().split(" ")) if P*2-1>C: print 0 continue elif P==1: print C%mo continue else: ret = 0 ret += hcomb(C-(P+P-1),P-1) ret += hcomb(C-(P+P),P)*2 ret += hcomb(C-(P+P+1),P+1) print ret % mo