#include<iostream>
using namespace std;
int dp[2003][2003];
int main()
{
int text;
cin>>text;
while(text--)
{
int n;
cin>>n;
int sum = 0;
int i,j;
for(i = 1;i <= n; i++ )
{
dp[i][1] = 1;
dp[i][i] = 1;
}
for(i = 3;i <= n;i++)
{
for(j = 2;j <= i-1;j++)
{
dp[i][j] = (dp[i-1][j-1] + dp[i-1][j] * j) %1000;
}
}
for(i = 1;i <= n;i++)
sum = (sum + dp[n][i])%1000;
cout<<sum%1000<<endl;
}
return 0;
}