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"
  "strings"
)

const mod int64 = 1000003
const size int = 40

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  q := input.NextInt()
  for k:=0;k<q;k++ {
    x,d,n := input.NextInts()
    if x == 0 { fmt.Println(0);continue }
    j := ((mod-x)*inv(d))%mod
    if n > j { fmt.Println(0);continue }
    m := x
    for i:=n-1;i>0;i-- { m = (m*(x+i*d)%mod)%mod }
    fmt.Println(m)
  }
}

func inv(n int64) int64 {
  if n == 1 { return 1 }
  k := make([]int64,size)
  a,b,u := mod,n,size
  for i:=0;i<size;i++ {
    k[i],a,b = a/b,b,a%b
    if b == 0 { u = i;break }
  }
  var y0,y1 int64 = 1,-k[0]
  for i:=1;i<u;i++ { y0,y1 = y1,y0-k[i]*y1 }
  for y1 < 0 { y1 += mod }
  return y1%mod
}

type Input struct {
  reader *bufio.Reader
}
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextInts() (int64,int64,int64) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.ParseInt(s[0],10,64)
  y,_ := strconv.ParseInt(s[1],10,64)
  z,_ := strconv.ParseInt(s[2],10,64)
  return x,y,z
}