import java.util.* ;
import java.lang.* ;
import java.io.* ;
class Main
{
static long MOD= 1000000 ;
static long [ ] [ ] multiply( long [ ] [ ] v1) {
long [ ] [ ] ans= new long [ 2 ] [ 2 ] ;
long x00 = v1[ 0 ] [ 0 ] ;
long x01 = v1[ 0 ] [ 1 ] ;
long x10 = v1[ 1 ] [ 0 ] ;
long x11 = v1[ 1 ] [ 1 ] ;
long res00, res01, res10, res11;
res00 = ( ( x00 * x00) % MOD + ( x10 * x01) % MOD) % MOD;
res01 = ( ( x00 * x01) % MOD + ( x01 * x11) % MOD) % MOD;
res10 = ( ( x10 * x00) % MOD + ( x10 * x11) % MOD) % MOD;
res11 = ( ( x10 * x01) % MOD + ( x11 * x11) % MOD) % MOD;
ans[ 0 ] [ 0 ] = ( res00+ MOD) % MOD;
ans[ 0 ] [ 1 ] = ( res01- MOD) % MOD;
ans[ 1 ] [ 0 ] = ( res10+ MOD) % MOD;
ans[ 1 ] [ 1 ] = ( res11- MOD) % MOD;
return ans;
}
static long [ ] [ ] pow_mod( long [ ] [ ] v, int p) {
if ( p == 1 ) return v;
//if ((p % 2) == 0)
return multiply( ( pow_mod( v, p / 2 ) ) ) ;
}
public static void main
( String [ ] args
) {
Scanner in
= new Scanner
( System .
in ) ;
int t= in.nextInt ( ) ;
for ( int i = 0 ; i < t; i++ )
{
int n= in.nextInt ( ) ;
if ( n % 3 != 0 )
{
}
else
{
n /= 3 ;
int p = 2 ;
long a1 = 1 , a2 = 1 ;
while ( n > 0 )
{
if ( ( n & 1 ) == 1 )
{
long [ ] [ ] a = { { 4 ,- 1 } ,{ 1 ,0 } } ;
a = pow_mod( a, p / 2 ) ;
long tmp1 = a1;
long tmp2 = a2;
a1 = ( tmp1 * a[ 0 ] [ 0 ] ) % MOD + ( tmp2 * ( ( a[ 0 ] [ 1 ] + MOD) % MOD) ) % MOD;
a2 = ( tmp1 * a[ 1 ] [ 0 ] ) % MOD + ( tmp2 * ( ( a[ 1 ] [ 1 ] + MOD) % MOD) ) % M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dIHYsIGludCBwKSB7CiAgICAgICAgaWYgKHAgPT0gMSkgcmV0dXJuIHY7CiAgICAgICAgLy9pZiAoKHAgJSAyKSA9PSAwKQogICAgICAgIHJldHVybiBtdWx0aXBseSgocG93X21vZCh2LCBwIC8gMikpKTsKICAgIH0KICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKQogICAgewogICAgICAgIFNjYW5uZXIgaW4gPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoKICAgICAgICBpbnQgdD1pbi5uZXh0SW50KCk7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCB0OyBpKyspCiAgICAgICAgewogICAgICAgICAgICBpbnQgbj1pbi5uZXh0SW50KCk7CiAgICAgICAgICAgIGlmIChuICUgMyE9MCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKDApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgbiAvPSAzOwogICAgICAgICAgICAgICAgaW50IHAgPSAyOwogICAgICAgICAgICAgICAgbG9uZyBhMSA9IDEsIGEyID0gMTsKICAgICAgICAgICAgICAgIHdoaWxlIChuID4gMCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZiAoKG4gJiAxKT09MSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxvbmdbXVtdIGEgPSB7IHs0LC0xfSx7MSwwfSB9OwogICAgICAgICAgICAgICAgICAgICAgICBhID0gcG93X21vZChhLCBwIC8gMik7CiAgICAgICAgICAgICAgICAgICAgICAgIGxvbmcgdG1wMSA9IGExOwogICAgICAgICAgICAgICAgICAgICAgICBsb25nIHRtcDIgPSBhMjsKICAgICAgICAgICAgICAgICAgICAgICAgYTEgPSAodG1wMSAqIGFbMF1bMF0pICUgTU9EICsgKHRtcDIgKiAoKGFbMF1bMV0gKyBNT0QpICUgTU9EKSkgJSBNT0Q7CiAgICAgICAgICAgICAgICAgICAgICAgIGEyID0gKHRtcDEgKiBhWzFdWzBdKSAlIE1PRCArICh0bXAyICogKChhWzFdWzFdICsgTU9EKSAlIE1PRCkpICUgTU9EOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBwICo9IDI7CiAgICAgICAgICAgICAgICAgICAgbiA+Pj0gMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGExPWExJU1PRDsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihhMSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0=