import re p=re.compile(r'\(|\)|,') M=10**9+7;U=2000001;F=[1] for i in xrange(1,U):F+=[(i*F[i-1])%M] FI=[pow(F[U-1],M-2,M)] for i in xrange(1,U):FI+=[(U-i)*FI[i-1]%M] for i in xrange(input()): q=p.split(raw_input());N,K=map(int,q[1:3]) if q[0]=="H": A = 1 if K==0 else F[N-1+K]*FI[U-N]*FI[U-1-K]%M*(N!=0) else: A = 0 if N < K else FI[U-1-K]**(q[0]=='C')*F[N]*FI[U-1-N+K]%M print A