atcoder#MSOLUTIONS2019E. Product of Arithmetic Progression

Product of Arithmetic Progression

Score : 600600 points

Problem Statement

Consider the following arithmetic progression with nn terms:

  • x,x+d,x+2d,,x+(n1)dx, 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 0031\ 000\ 003.

You are given QQ queries of this form. In the ii-th query, compute the answer in case x=xi,d=di,n=nix = x_i, d = d_i, n = n_i.

Constraints

  • 1Q1051 \leq Q \leq 10^5
  • 0xi,di1 000 0020 \leq x_i, d_i \leq 1\ 000\ 002
  • 1ni1091 \leq n_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

QQ

x1x_1 d1d_1 n1n_1

::

xQx_Q dQd_Q nQn_Q

Output

Print QQ lines.

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

2
7 2 4
12345 67890 2019
9009
916936

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