复杂度O(logn);
#include <cstdio>
#define mod 10003
int f(int a, int n){
if(n == 0) return 1 % mod;
if(n == 1) return a % mod;
int t = f(a, n / 2);
t = t * t % mod;
if(n & 1) return t * a % mod;
return t;
}
int main(){
int t, a, n, s, i;
scanf("%d", &t);
while(t-- && scanf("%d%d", &n, &a)){
for(i = 1, s = 0; i <= n; ++i)
s += f(i, a), s %= mod;
printf("%d\n", s);
}
return 0;
}