Problem:
Score : 600 points

Problem Statement

Consider the following arithmetic progression with n terms:

x, x + d, x + 2d, \ldots, x + (n-1)d

What is the product of all terms in this sequence?
Compute the answer modulo 1\ 000\ 003.

You are given Q queries of this form.
In the i-th query, compute the answer in case x = x_i, d = d_i, n = n_i.

Constraints

1 \leq Q \leq 10^5

0 \leq x_i, d_i \leq 1\ 000\ 002

1 \leq n_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
x_1 d_1 n_1
:
x_Q d_Q n_Q

Output

Print Q lines.

In the i-th line, print the answer for the i-th query.

Sample Input 1

2
7 2 4
12345 67890 2019

Sample Output 1

9009
916936

For the first query, the answer is 7 \times 9 \times 11 \times 13 = 9009.
Don't forget to compute the answer modulo 1\ 000\ 003.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000003;
    vector<unsigned long> fr(MOD, 1), inv(MOD, 1), ifr(MOD, 1);
    iota(fr.begin() + 1, fr.end(), 1UL);
    for(unsigned long i = 2; i < MOD; ++i)inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
    partial_sum(fr.begin(), fr.end(), fr.begin(), [&MOD](auto a, auto b){return a * b % MOD;});
    partial_sum(inv.begin(), inv.end(), ifr.begin(), [&MOD](auto a, auto b){return a * b % MOD;});
    unsigned long Q;
    cin >> Q;
    auto modpow = [&MOD](auto a, auto b, auto n){
        a %= MOD;
        while(n){
            if(n & 1)(a *= b) %= MOD;
            (b *= b) %= MOD;
            n >>= 1;
        }
        return a;
    };
    for(unsigned long iter = 0, x, d, n; iter < Q; ++iter){
        cin >> x >> d >> n;
        auto beg = (inv[d] * x + MOD - 1) % MOD;
        cout << (d ? beg + n >= MOD ? 0 : modpow(fr[beg + n] * ifr[beg], d, n) : modpow(1, x, n)) << endl;
    }
    return 0;
}