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>

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000003;
#define MAX_X 1000010

struct mint {
    ll x;
    mint(ll x = 0) : x(x % MOD) {}
    mint& operator += (const mint a) {
        if ( (x += a.x) >= MOD) { x -= MOD; }
        return *this;
    }
    mint& operator -= (const mint a) {
        if ( (x += MOD - a.x) >= MOD) { x -= MOD; }
        return *this;
    }
    mint& operator *= (const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator + (const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator - (const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator * (const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

// x の y 乗を求める O(log MOD)
ll modpow(ll x, ll y) {
    if (y == 0) return 1;
    ll res = modpow(x, y / 2);
    return res * res % MOD * (y & 1 ? x : 1) % MOD;
}
// x の逆元を求める O(logMOD)
ll modinv(ll x) { return modpow(x, MOD - 2); }
mint modinv(mint x) { return modpow(x.x, MOD - 2); }

ll Q;

vector<mint> fact;    // 階乗 i!

ll solve(ll x, ll d, ll n) {
    // 等差数列の積は d^n * ( (x/d + n - 1)! / (x/d - 1)! ) である
    mint x_d = mint(x) * mint(modinv(d));

    // d が 0 のときは例外 -> x^n になる
    if(d == 0) { return modpow(x, n); }

    // 剰余の関係上 MAX_X! 以上の階乗は 0 になる
    if((x_d + n - 1).x >= MOD) { return 0; }

    mint ret = modpow(d, n);
    ret *= fact[ (x_d + n - 1).x ];
    ret *= modinv(fact[ (x_d - 1).x ]);

    return ret.x;
}

signed main()
{
    cin >> Q;

    // fact の作成
    fact.resize(MAX_X);
    fact[0] = 1;
    fact[1] = 1;
    for(int i = 2; i < MAX_X; ++i) {
        fact[i] = fact[i-1] * i;
    }

    REP(i, Q) {
        ll x, d, n;
        cin >> x >> d >> n;
        ll ans = solve(x, d, n);
        printf("%lld\n", ans);
    }
    return 0;
}