Problem:
Score : 600 points

Problem Statement

Given is an integer N. Snuke will choose integers s_1, s_2, n_1, n_2, u_1, u_2, k_1, k_2, e_1, and e_2 so that all of the following six conditions will be satisfied:

0 \leq s_1 < s_2

0 \leq n_1 < n_2

0 \leq u_1 < u_2

0 \leq k_1 < k_2

0 \leq e_1 < e_2

s_1 + s_2 + n_1 + n_2 + u_1 + u_2 + k_1 + k_2 + e_1 + e_2 \leq N

For every possible choice (s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2), compute (s_2 − s_1)(n_2 − n_1)(u_2 − u_1)(k_2 - k_1)(e_2 - e_1), and find the sum of all computed values, modulo (10^{9} +7).

Solve this problem for each of the T test cases given.

Constraints

All values in input are integers.

1 \leq T \leq 100

1 \leq N \leq 10^{9}

Input

Input is given from Standard Input in the following format:

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

Each case is given in the following format:

N

Output

Print T lines. The i-th line should contain the answer to the i-th test case.

Sample Input 1

4
4
6
10
1000000000

Sample Output 1

0
11
4598
257255556

When N=4, there is no possible choice (s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2). Thus, the answer is 0.

When N=6, there are six possible choices (s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2) as follows:

(0,1,0,1,0,1,0,1,0,1)

(0,2,0,1,0,1,0,1,0,1)

(0,1,0,2,0,1,0,1,0,1)

(0,1,0,1,0,2,0,1,0,1)

(0,1,0,1,0,1,0,2,0,1)

(0,1,0,1,0,1,0,1,0,2)

We have one choice where (s_2 − s_1)(n_2 − n_1)(u_2 − u_1)(k_2 - k_1)(e_2 - e_1) is 1 and five choices where (s_2 − s_1)(n_2 − n_1)(u_2 − u_1)(k_2 - k_1)(e_2 - e_1) is 2, so the answer is 11.

Be sure to find the sum modulo (10^{9} +7).

Solution in Rust (1.42.0) (judge verdict: Accepted)

// ${url}
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! read_line {
    ($t:tt) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().parse::<$t>().unwrap()
        }
    }
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// ===

// ===

const MOD: i64 = 1e9 as i64 + 7;

type SquareMatrix = Vec<Vec<i64>>;

fn eye(n: usize) -> SquareMatrix {
    let mut data = dvec!(0; n, n);
    for i in 0..n {
        data[i][i] = 1;
    }
    data
}

fn pow(a: SquareMatrix, mut n: i64) -> SquareMatrix {
    let mut ret = eye(a.len());
    let mut aa = a.clone();
    while n >= 1 {
        if n & 1 == 1 {
            ret = multiply(&ret, &aa);
        }
        aa = multiply(&aa, &aa);
        n /= 2;
    }
    ret
}

fn multiply(left: &SquareMatrix, right: &SquareMatrix) -> SquareMatrix {
    let mut temp = dvec![0; 64, 64];
    let n = left.len();
    let mod2 = MOD*MOD;
    for i in 0..n {
        for k in 0..n {
            for j in 0..n {
                temp[i][j] += left[i][k] * right[k][j];
                if temp[i][j] >= mod2 {
                    temp[i][j] -= mod2;
                }
            }
        }
    }
    for i in 0..n {
        for j in 0..n {
            temp[i][j] %= MOD;
        }
    }
    temp
}

fn multiply_one(left: &SquareMatrix, w: &Vec<i64>) -> Vec<i64> {
    let n = w.len();
    let mut ret = vec![0; n];
    let mod2 = MOD*MOD;
    for i in 0..n {
        for j in 0..n {
            ret[i] += left[i][j] * w[j];
            if ret[i] >= mod2 {
                ret[i] -= mod2
            }
        }
        ret[i] %= MOD;
    }
    ret
}

//===

fn add(from: usize, to: usize, mat: &mut SquareMatrix) {
    mat[to][from] += 1;
}

fn encode(phase: usize, flag: usize) -> usize {
    phase * 2 + flag
}

const MAX_SIZE: usize = 21;

fn main() {
    input! {
        n: usize,
        a: [i64; n]
    };

    let mut mat = dvec![0; MAX_SIZE, MAX_SIZE];
    for i in 0..5 {
        for mod2 in 0..2 {
            // place same
            add(encode(i, mod2), encode(i, mod2^1), &mut mat);
            // go next
            for j in i+1..=5 {
                if mod2 == 0 {
                    continue;
                }
                add(encode(i, mod2), encode(j, mod2^1), &mut mat);
            }
        }
    }
    for i in 5..10 {
        for placed in 0..2 {
            for to_placed in 0..2 {
                if placed == 1 && to_placed == 0 {
                    continue;
                }
                add(encode(i, placed), encode(i, to_placed), &mut mat);
            }
            add(encode(i, placed), encode(i+1, 0), &mut mat);
        }
    }
    add(encode(10, 0), encode(10, 0), &mut mat);

    let mut ans = vec![0; n];
    let mut a = a.into_iter().zip(0..n).collect::<Vec<_>>();
    a.sort();

    let mut last_size = 0;
    let mut table = eye(MAX_SIZE);

    for (l, idx) in a {
        let mut one = vec![0; MAX_SIZE];
        for phase in 0..=5 {
            one[encode(phase, 0)] = 1;
        }
        if last_size < l {
            table = multiply(&table, &pow(mat.clone(), l-last_size));
            last_size = l;
        }
        ans[idx] = multiply_one(&table, &one)[encode(10, 0)];
    }

    for i in 0..n {
        println!("{}", ans[i]);
    }
}