#include <cstdio>
int ans[1000001];
int main(void)
{
ans[0] = 1, ans[1] = 1;
for(int i=2; i<=1000000; ++i)
ans[i] = (ans[i-1] + ((long long)(i-1) * ans[i-2])) % 1000000007;
int tt;
scanf("%d", &tt);
for(int t=1; t<=tt; ++t) {
int i;
scanf("%d", &i);
printf("Case #%d:\n%d\n", t, ans[i]);
}
return 0;
}