#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; #include<vector> /* This function calculates power of p in n! */ int countFact(int n, int p) { int k=0; while (n>=p) { k+=n/p; n/=p; } return k; } /* This function calculates (a^b)%MOD */ long long pow(int a, int b, int MOD) { long long x=1,y=a; while(b > 0) { if(b%2 == 1) { x=(x*y); if(x>MOD) x%=MOD; } y = (y*y); if(y>MOD) y%=MOD; b /= 2; } return x; } /* Modular Multiplicative Inverse Using Euler's Theorem a^(phi(m)) = 1 (mod m) a^(-1) = a^(m-2) (mod m) */ long long InverseEuler(int n, int MOD) { return pow(n,MOD-2,MOD); } long long factMOD(int n, int MOD) { long long res = 1; while (n > 0) { for (int i=2, m=n%MOD; i<=m; i++) res = (res * i) % MOD; if ((n/=MOD)%2 > 0) res = MOD - res; } return res; } long long C(int n, int r, int MOD) { if (countFact(n, MOD) > countFact(r, MOD) + countFact(n-r, MOD)) return 0; return (factMOD(n, MOD) * ((InverseEuler(factMOD(r, MOD), MOD) * InverseEuler(factMOD(n-r, MOD), MOD)) % MOD)) % MOD; } int main() { int n,r,t, k; k = scanf("%d",&t); while (t--) { k = scanf("%d %d",&n,&r); if (n < 2*r - 1) printf("0\n"); else printf("%lld\n",C(n+1 -r ,r,100003)); } }