#include
#include
#define MAX 1000000 + 2
char s[MAX];
//模拟取余
int Simu(int n){
int t = 0, len = strlen(s);
for(int i = 0; i != len; ++i){
t = t * 10 + s[i] - '0';
t %= n;
}
return t;
}
int main(){
int t, x;
scanf("%d", &t);
while(t-- && scanf("%s", s))
printf("%d
", Simu(10003));
return 0;
}