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 LuaJIT (2.0.4) (judge verdict: Accepted)

local bls, brs = bit.lshift, bit.rshift
local mod = 1000003
local function badd(x, y) return (x + y) % mod end
local function bmul(x, y) return (x * y) % mod end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = brs(pow, 1)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local fact = {1}
for i = 2, mod - 1 do
  fact[i] = bmul(fact[i - 1], i)
end

local q = io.read("*n")
for iq = 1, q do
  local x, d, n = io.read("*n", "*n", "*n")
  if d == 0 then
    print(modpow(x, n))
  else
    local a = bmul(x, modinv(d))
    local lim = a + n - 1
    if mod <= lim then
      print(0)
    else
      local numer = fact[lim]
      numer = bmul(numer, modpow(d, n))
      local denom = 1
      if 1 < a then
        denom = fact[a - 1]
      end
      local ret = bmul(numer, modinv(denom))
      print(ret)
    end
  end
end