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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int Q = int.Parse(Console.ReadLine());
		long[]NA = new long[1000010];
		long[]INA = new long[1000010];
		long mod = 1000003;
		NA[0] = 1;
		INA[0] = 1;
		for(var i=1;i<1000010;i++){
			NA[i] = NA[i-1] * i % mod;
			INA[i] = INA[i-1] * Mpow(i,mod-2,mod) % mod;
		}
		for(var i=0;i<Q;i++){
			string[] str = Console.ReadLine().Split();
			long X = long.Parse(str[0]);
			long D = long.Parse(str[1]);
			long N = long.Parse(str[2]);
			long ans;
			if(D==0){
				ans = Mpow(X,N,mod);
			} else {
				ans = NA[(X*Mpow(D,mod-2,mod)+N-1)%mod] * INA[(X*Mpow(D,mod-2,mod)+mod-1)%mod] % mod;
              	ans = ans * Mpow(D,N,mod) % mod;
			}
			Console.WriteLine(ans);
		}
	}
	
	public static long Mpow(long x,long n,long m)
	{
		long ans = 1;
		while(n > 0){
			if(n % 2 == 1){
				ans = ans * x % m;
				n -= 1;
			}
			x = x * x % m;
			n /= 2;
		}
		return ans;
	}
}