birthday-party-6

Today is Sid’s birthday and he is very excited about this as he is giving a special birthday party to all his friends. In this party they are going to play a game for which Sid have to arrange all his friends in a row such that no two boys should be present which are adjacent to each other. There are total M girls and N boys in the party excluding the Sid.

You are his best friend Sonu and he is asking for your help to find the number of ways he can arrange his friends in a row according to the given condition.

If no  such arrangement is possible, print -1.

Input
The first line contains one number T representing the number of test cases.
Each test case contains two integers, M representing the number of girls and N representing the number of boys.

Output
For each test case, you need to find the number of different ways to arrange Sid’s friends. As the answer can be very large you need to print the  answer modulo (1000000007).

Constraints
1 ≤ T ≤ 100000
1 ≤ M ≤ 50
1 ≤ N ≤ 50

SAMPLE INPUT
1
3 2

SAMPLE OUTPUT
72

Source: hackerearth | Difficulty: EASY


Solutions:
t=int(input())
k=1000000007
while (t>0):
	m,n=(input().split())
	m,n=[int(m),int(n)]
	res=1;
	if m>=n-1:
		for i in range(m+1-n+1,m+2):
			res=(res*i)%k
		for i in range(1,m+1):
			res=(res*i)%k
		print(res)
	else:
		print((-1))
	t=t-1;
	
		
	
	
	
	
	



from math import factorial as fact

t = eval(input())

for i in range(t):
	m, n = (int(i) for i in input().split())
	if m+1-n >=0:
		mfact = fact(m) 
		off = mfact * (m+1)
		bottom = fact((m+1-n))
		pnrpart = (off/bottom)
		ans = (mfact * pnrpart) % 1000000007
		print(ans)
	else:
		print(-1)


mod =1000000007;
fact=[];

def fact_mod(n):
	fact.append(1)
	for i in range(1,n+2):
		fact.append(i*fact[i-1]%mod)

def ncr(n,r):
	ans =fact[n]*pow(fact[r]*fact[n - r], mod - 2, mod)%mod
	return	 ans;

fact_mod(51);
k  = int(input())
for i in range (0 , k ):
		str = input().split(" ");
		m = int(str[0]); #girls
		n = int(str[1]); #boys
		if(n>m+1) :
			print("-1");
		else :
			fact_n = fact[n];
			fact_m = fact[m];
			factncm = ncr(m+1,n);
			# print fact_n; 
			# print fact_m;
			# print factncm;
			ans = ((fact_m*fact_n)%mod*factncm)%mod;
			print(ans);


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
c = 1000000007
def fact(cache):
	cache[0] = 1
	for i in range(1, 51+1):
		cache[i] = cache[i-1] * i

cache = [i for i in range(0, 55)]
fact(cache)
t = eval(input())
for i in range(0, t):
	l = input().split(' ');
	g = int(l[0])
	b = int(l[1])
	if(g < b-1):
		print(-1)
	else:
		print((cache[g] * (cache[g+1]/ (cache[b] * cache[g+1-b])) * cache[b] ) % c)


import math
def nCr(n, r) :
	return math.factorial(n) / (math.factorial(r) * math.factorial(n-r))
T = int(input())
for _ in range(T) :
	M, N = input().split()
	M, N = int(M), int(N)
	if N >= M + 2 :
		print(-1)
	else :
		print((nCr(M+1, N) *  math.factorial(M) * math.factorial(N))%1000000007)


factorial = [1]
def fact():
	f=1
	global factorial
	loop=1
	while(loop<=52):
		
		f*=loop
		factorial.append(f)
		loop+=1
fact()
	
lines = int(input())
while(lines>0):
    lines -= 1
    row = input().split()
    m = int(row[0])
    n = int(row[1])
    
    if(n-1<=m):
    	girlcombinations = factorial[m]
    	h = factorial[m+1]
    	r = factorial[m+1-n]
    	boycombinations = h/r
    	print(girlcombinations*(boycombinations)%1000000007)
    	
    else:#no possibilittes 
    	print(-1)


from math import factorial as fact

t = eval(input())

for i in range(t):
	m, n = (int(i) for i in input().split())
	if n - m <=1:
		mfact = fact(m) 
		off = mfact * (m+1)
		bottom = fact((m+1-n))
		pnrpart = (off/bottom)
		ans = (mfact * pnrpart) % 1000000007
		print(ans)
	else:
		print(-1)


from math import factorial as fact

t = eval(input())

for i in range(t):
	m, n = (int(i) for i in input().split())
	if n - m <=1:
		mfact = fact(m) 
		off = fact((m+1))
		bottom = fact((m+1-n))
		pnrpart = (off/bottom)
		ans = (mfact * pnrpart) % 1000000007
		print(ans)
	else:
		print(-1)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
test=int(input(''))
def findfact(n):
	i=1
	fact=1
	while(n>1):
		fact=(fact*n)
		n=n-1
	return fact
	
for i in range(test):
	input=input('')
	l=input.split(' ')
	g=int(l[0])
	b=int(l[1])
	
	if(b>g+1):
		print(-1)
	
	else:
		sol=((findfact(g) *findfact(b)*findfact(g+1)))/((findfact(b)*findfact(g+1-b)))%1000000007
		print(sol)
		





import math
f = math.factorial

def nPr(n,r):
	return f(n) / f(n-r)
	
for _ in range(eval(input())):
	g , b = list(map(int, input().split()))
	if g+1 < b :
		print('-1')
	else:
		print((f(g)*nPr(g+1,b))%1000000007)
	
	
	


import sys
fact=[0]*200
fact[0]=1
fact[1]=1
comb= [[0 for x in range(62)] for x in range(62)] 

comb[0][0]=0
comb[1][0]=0
for i in range(1,62):
	comb[i][i]=1
	comb[i][0]=1
for i in range(2,60):
	for j in range(1,i+1):
		comb[i][j]=comb[i-1][j]+comb[i-1][j-1]
		comb[i][j]%=1000000007


for i in range(2,200):
	fact[i]=i*fact[i-1];
	fact[i]=fact[i]%1000000007
t=int(input());
while(t>0):
	m,n=list(map(int, sys.stdin.readline().split(" ")));
	
	
	val3=-1
	if(m+1<n):
		print(val3)
	else:
		val=comb[m+1][n]*fact[m]*fact[n]
		val%=1000000007
		print(val)
	t-=1
		
		
	
	


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import math
t=eval(input())
while(t>0):
	t=t-1
	m,n=list(map(int,input().split()))
	if n <= m+1:
		gls=math.factorial(m)
		bys=gls*(m+1)
		print(((bys*gls)/math.factorial(m+1-n))%1000000007)
	else:
		print(-1)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import math
T = eval(input())
for i in range(T):
	line = input()
	M, N = line.split()
	M, N = int(M), int(N)
	if N >= M + 2:
		print(-1)
	else:
		res_num = pow(math.factorial(M),2) * (M+1)
		if N >= M + 1:
			den = 1
		else:
			den= math.factorial(M + 1 -N)
		res = res_num / den
		if res > 1000000007:
			res = res % 1000000007
		print(res)
	
	


def memoize(f):
	memo = dict()
	def wrapper(n):
		if memo.get(n) is None :
			memo[n] = f(n)
		return memo[n]
	return wrapper

@memoize
def factorial(n):
	if n == 0:
	   return 1
	else:
	   return n*factorial(n-1)

def combination(n,r):
	return factorial(n)/(factorial(r) * factorial(n-r))

testcases = int(input())
for testcase in range(testcases):
	(girls, boys) = list(map(int,input().split()))
	if girls+1 < boys :
		print("-1")
	else:
		print((factorial(girls) * combination(girls+1,boys) * factorial(boys))%1000000007)




t=int(eval(input()))

def fac(n):
	pro=1
	for i in range(1,n+1):
		pro=pro*i
		pro=pro%1000000007
	return pro
def per(n,r):
	pro=1
	for i in range(0,r):
		pro=pro*(n-i)
		pro=pro%1000000007
	return pro
while t>0:
	r=input().split()
	g=int(r[0])
	b=int(r[1])
	if(g-b<-1):
		print("-1")
	else :
		pro=per(g+1,b)*fac(g)
		pro=pro%1000000007
		print(pro)
	t-=1


def fact(num):
	fact=1    
	for i in range (1,num+1):
		fact=fact*i
	return fact


T=eval(input())
arr=[]
for i in range (1,T+1):
	#print i
	
	str=input()
	#X=input()
	N, X = str.split()
	N=int(N)
	X=int(X)
	if N<(X-1):
		arr.append("-1")
	else:	
		arr.append((fact(N)* (fact(N+1)/ fact(N+1-X)))%1000000007)
	#temp=0

for i in range (1,T+1):
	print(arr[i-1])
	#


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import math

def nCr(n,r):
	f = math.factorial
	return f(n) / f(r) / f(n-r)

def main():
	test_cases = int(input())
	girls = 0
	boys = 0
	for i in range(test_cases):
		input = input().split(' ')
		try:
			girls = int(input[0])
			boys = int(input[1])
	
			space_for_boys = girls + 1
			no_of_ways = math.factorial(girls) * math.factorial(boys) * nCr(space_for_boys, boys)
		
			print(no_of_ways % 1000000007)
		except:
			print(-1)
	
if __name__ == '__main__':
	main()


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''

import math
def perm(n,k):
	return int(math.factorial(n)/math.factorial(n-k))

def ways():
	str=input()
	m=int(str.split(" ")[0])
	n=int(str.split(" ")[1])
	if((m+1)>=n):
		return ((math.factorial(m)*perm(m+1,n))%1000000007)
	else:
		return -1

t=int(input())
while(t>0):
	t=t-1
	print((ways()))


t=int(input())
k=1000000007
while(t>0):
	m,n=(input().split())
	m,n=[int(m),int(n)]
	res=1;
	if m>=n-1:
		for i in range (m+1-n+1,m+2):	
	   		res=(res*i)%k
		for i in range (1,m+1):
			res=(res*i)%k
		print(res)
	else:
		print((-1))
	t=t-1