#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod = 1000000007;
long long f[1000100];
int main()
{
f[1] = 1;
f[2] = 2;
for(int i = 3; i <= 1000000;i++)
f[i] = (f[i-1] +(f[i-2])*(i-1))%mod;
int T,n;
scanf("%d",&T);
for(int cas = 1; cas <= T;cas++){
scanf("%d",&n);
printf("Case #%d:\n%lld\n",cas,f[n]);
}
return 0;
}