# coding:utf-8 MOD = 1000000007 fact = [1]*2000010 inv = [1]*2000010 invfact = [1]*2000010 for i in range(2, 2000010, 1): inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD fact[i] = fact[i-1]*i%MOD invfact[i] = invfact[i-1]*inv[i]%MOD def c(n, r): if r<0 or r>n: return 0 return fact[n]*invfact[r]*invfact[n-r]%MOD def p(n, r): if r<0 or r>n: return 0 return fact[n]*fact[n-r]%MOD def h(n, r): if n==0 and r==0:return 1 return c(n+r-1, r) T = int(input()) for i in range(T): s = input() x = s[0] n, k = map(int, s[2:-1].split(',')) if x=="C": print(c(n, k)) if x=="P": print(p(n, k)) if x=="H": print(h(n, k))