//my top down code correct but giving wa
import java.util.Arrays;
import java.util.Scanner;
public class FriendPairing {
public static int f(int n,int[]dp) {
if(n==0)return 1;
if(n==1)return 1;
if(n==2)return 2;
if(dp[n]!=-1)
return dp[n];
dp[n]=f(n-1,dp)+f(n-2,dp)*(n-1);
return dp[n];
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++) {
int n=sc.nextInt();
int[] dp=new int[n+1];
Arrays.fill(dp,-1);
System.out.println(f(n,dp));
}
}
}
//my bottom up code correct but giving issue
import java.util.Arrays;
import java.util.Scanner;
public class FriendsPairingBU {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++) {
int n=sc.nextInt();
int[] dp=new int[n+2];
for(int j=0;j<n+2;j++) {
dp[j]=-1;
}
dp[0]=1;
dp[1]=1;
dp[2]=2;
for(int j=3;j<n+1;j++) {
dp[j]=(j-1)*dp[j-2]+dp[j-1];
}
System.out.println(dp[n]);
}
}
}