#T154. Pell数列

Pell数列

Description

The Pell sequence a1,a2,a3,a_1, a_2, a_3, \dots is defined as follows: a1=1a_1 = 1, a2=2a_2 = 2, and an=2an1+an2a_n = 2a_{n-1} + a_{n-2} for n>2n > 2.
Given a positive integer kk, find the value of the kk-th term in the Pell sequence modulo 32767.

Input Format

The first line contains the number of test cases nn, followed by nn lines of input. Each test case consists of a single line containing a positive integer kk (1k<1,000,0001 \leq k < 1,000,000).

Output Format

Output nn lines, each corresponding to an input. Each line should contain a non-negative integer.

2
1
8


1
408