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: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Modular
    {
        private const int M = 1000003;
        private long value;

        public Modular(long value) { this.value = value; }
        public static implicit operator Modular(long a) { return new Modular((a % M + M) % M); }
        public static Modular operator +(Modular a, Modular b) { return a.value + b.value; }
        public static Modular operator -(Modular a, Modular b) { return a.value - b.value; }
        public static Modular operator *(Modular a, Modular b) { return a.value * b.value; }
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
            }
        }
        public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); }
        private static readonly List<int> facs = new List<int> { 1 };
        public static Modular Fac(int n)
        {
            for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); }
            return facs[n];
        }
        public static Modular Ncr(int n, int r)
        {
            return (n < r) ? 0
                 : (n == r) ? 1
                            : Fac(n) / Fac(r) / Fac(n - r);
        }
        public static explicit operator int(Modular a) { return (int)a.value; }
    }

    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static Modular Pi(int x, int n)
        {
            return (x > 0 && n < 1000002) ? Modular.Fac(x + n) / Modular.Fac(x - 1) : 0;
        }

        static int Solve(int x, int d, int n)
        {
            if (d == 0)
            {
                return (int)Modular.Pow(x, n);
            }
            else
            {
                var X = new Modular(x) / d;
                return (int)(Modular.Pow(d, n) * Pi((int)X, n - 1));
            }
        }

        static void Main(string[] args)
        {
            int Q = ReadInt();
            for (int i = 0; i < Q; ++i)
            {
                int[] V = ReadInts();
                Console.WriteLine(Solve(V[0], V[1], V[2]));
            }
        }
    }
}