import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); Combination cmb = new Combination(2000000); StringBuilder sb = new StringBuilder(); for (int i = 0; i < t; i++) { String str = sc.next(); char c = str.charAt(0); String[] line = str.substring(2, str.length() - 1).split(",", 2); int x = Integer.parseInt(line[0]); int y = Integer.parseInt(line[1]); if (c == 'C') { sb.append(cmb.getComb(x, y)).append("\n"); } else if (c == 'H') { sb.append(cmb.getComb(x + y - 1, y)).append("\n"); } else { sb.append(cmb.getPlace(x, y)).append("\n"); } } System.out.print(sb); } } class Combination { static final int MOD = 1000000007; long[] fac; long[] finv; long[] inv; public Combination (int size) { fac = new long [size]; finv = new long [size]; inv = new long [size]; fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < size; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } public long getComb(int n, int k) { if (n < k || n < 0 || k < 0) { return 0; } return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } public long getPlace(int n, int k) { if (n < k || n < 0 || k < 0) { return 0; } return fac[n] * finv[n - k] % MOD; } }