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 Go (1.6) (judge verdict: Runtime Error)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	mod = int64(1000003)
)

func pow(x, y int64) int64 {
	if y == 0 {
		return 1
	}
	if y == 1 {
		return x
	}
	if y%2 == 0 {
		x2 := x * x % mod
		return pow(x2, y/2) % mod
	}
	return x * pow(x, y-1) % mod
}

func divide(x, y int64) int64 {
	return x * pow(y, mod-2) % mod
}

func main() {
	var q int
	fmt.Scan(&q)

	factorial := make([]int64, mod)
	factorial[0] = 1
	for i := int64(1); i < mod; i++ {
		factorial[i] = factorial[i-1] * i % mod
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	for i := 0; i < q; i++ {
		scanner.Scan()
		xi, _ := strconv.Atoi(scanner.Text())
		x := int64(xi)
		scanner.Scan()
		di, _ := strconv.Atoi(scanner.Text())
		d := int64(di)
		scanner.Scan()
		ni, _ := strconv.Atoi(scanner.Text())
		n := int64(ni)

		if d == 0 {
			fmt.Println(pow(x, n))
			break
		}
		
		xdd := divide(x, d)
		ret := int64(1)
		for j := xdd; j < xdd+n; j++ {
			if j%mod == 0 {
				fmt.Println(0)
				break
			}
			ret = ret * j % mod
		}
		ret = divide(factorial[xdd+n-1], factorial[xdd-1]) % mod
		ret = ret * pow(d, n) % mod
		fmt.Println(ret)
	}
}