enum{m=100003};n,i,b[m],q,c,d;long long a[m],v[m];unsigned x=123456789,y=362436069,z=521288629,w=88675123,t;main(_){for(v[i=1]=1;++i>19^t^t>>8;for(;_--;printf("%d\n",c)){scanf("%d",&q);c=0;if(n<99){for(i=n;i--;c=c>d?c:d)d=a[i]*q%m;}else if(q){for(c=m;--c*!b[c*v[q]%m];);}}}