Under construction

Still being built. Things may change

Lines in a grid

Time limit8sMemory limit1024 MB

Summary
Count the distinct lines through at least two points of an n by n integer grid for each query n, modulo 1000003.
Level

Medium7 of 10

Topics
Math, Number theory, Combinatorics
Solved
No attempts yet

Problem

Suppose that we are given an n×nn \times n integer grid, for example {(i,j)}i=0,j=0n−1,n−1\{(i, j)\}_{i=0, j=0}^{n-1, n-1}. Let lnl_n be the number of different lines that intersect at least two points of the grid.

For n=3n = 3, there are exactly 20 such lines, as drawn in the image below.

Compute lnl_n for all given nn.

Input

The first line contains an integer QQ, the number of queries. The second line contains QQ space-separated integers n1,…,nQn_1, \dots, n_Q.

Output

Print QQ numbers ln1,…,lnQl_{n_1}, \dots, l_{n_Q}, each on its own line. Since lkl_k can be large, print each value modulo 106+310^6 + 3.

Constraints

1≤Q≤10001 \le Q \le 1000

1≤ni≤1071 \le n_i \le 10^7

Examples1

  1. Example 1

    Input
    3
    1 3 2
    
    Expected output
    0
    20
    6