import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int t = sc.nextInt();
long[] ans = new long[1000001];
long mod = 1000000007l;
ans[1] = 1;
ans[2] = 2;
int m = 3;
for (int i = 1; i <= t; i++) {
int n = sc.nextInt();
while (m <= n) {
ans[m] = mod(ans[m-1] + (m-1)*ans[m-2]); //用mod函数会稍微快点,但是不影响结果
m++;
}
System.out.println("Case #"+i+":");
System.out.println(ans[n]);
// System.out.println("Case #"+i+":\n"+ans[n]);//这种形式会报格式错误
}
}
}
public static long mod(long i) {
return i%1000000007;
}
}
/**TLE 递归影响时间,改成dp
public static int find(int n) {
if (n == 1)
return 1;
if (n == 2)
return 2;
else
return mod(find(n-1))+mod((n-1)*find(n-2));
}
*/