roy-and-ring-13

Roy bought a Ring for Alfi, his girlfriend :p. But Alfi will only accept the Ring if Roy played a game with her and answered her queries correctly during the game.

Alfi places a ring at origin of a Cartesian Plane. Both Alfi and Roy move the ring alternatively.
Alfi takes odd steps and Roy takes even steps. 

Direction of Movement:
Alfi always moves either left or right alternatively, i.e. if she moved left in her last step, she will move right in her current step. Initially she moves right. Roy always moves up or down alternatively, i.e if he moved up in his last step, he will move down in his current step. Initially he moves up.

Displacement of Ring:
Initially both of them displace the ring by 1 unit.
During Alfi's turn(other than her first step), she sums up her last displacement and Roy's last displacement, and moves the Ring by the value thus obtained.
Similary, during Roy's turn(other than his first step), he sums up his last displacement and Alfi's last displacement, and moves the Ring by the value thus obtained.

Sample example of movements:

Now that the direction and displacement of Ring's movements are clear. Its time to answer Alfi's weird queries.

Given the step number N, what is the perpendicular distance of Ring from Y-axis after that step.
Now Alfi is such an impatient girl, she wants him to answer as quickly as possible, otherwise she won't accept the Ring.

Input:

First line of input will contain integer Q, number of queries.
Next Q lines each will contain integer  N, step number of the game.

Output:

Print the result of each query in a new line.
Since the result can be very large, print it modulo 1000000007

Constraints:

1 ≤ Q ≤ 10000

1 ≤ N ≤ 1000000000

SAMPLE INPUT
4
1
2
3
4

SAMPLE OUTPUT
1
1
1
1

Explanation

From the figure its clear that perpendicular distance of Ring from Y-axis  after steps 1, 2, 3 and 4 are all 1.

Source: hackerearth | Difficulty: MEDIUM
Tags: Matrices

Mathematics

Ad-hoc


Solutions:
MOD = 1000000007
def matrix_mul(a,b,c):
	c[0][0] = a[0][0]*b[0][0] + a[0][1]*b[1][0]
	c[0][0] %= MOD
	c[0][1] = a[0][0]*b[0][1] + a[0][1]*b[1][1]
	c[0][1] %= MOD
	c[1][0] = a[1][0]*b[0][0] + a[1][1]*b[1][0]
	c[1][0] %= MOD
	c[1][1] = a[1][0]*b[0][1] + a[1][1]*b[1][1]
	c[1][1] %= MOD

def iter_pow(n):
	a = [[1,0],[0,1]]
	b = [[1,1],[1,0]]
	c = [[0,0],[0,0]]
	while(n):
		if(n&1):
			matrix_mul(a,b,c)
			a[0][0] = c[0][0]
			a[0][1] = c[0][1]
			a[1][0] = c[1][0]
			a[1][1] = c[1][1]
		matrix_mul(b,b,c)
		b[0][0] = c[0][0]
		b[0][1] = c[0][1]
		b[1][0] = c[1][0]
		b[1][1] = c[1][1]
		n = n>>1
	return a[0][1]%MOD

def roy_and_ring():
	for q in range(eval(input())):
		n = eval(input())
		n = (n+1)/2
		res = iter_pow(n)
		res *= res
		res %= MOD
		print(res)
roy_and_ring()