#include <iostream>
using namespace std;
int ans[1000050] = {0, 1, 2};
int f(int n)
{
if (ans[n])
return ans[n];
ans[n] = (2 * f(n - 1) + f(n - 2)) % 32767;
return ans[n];
}
int main()
{
int n, a;
cin >> n;
while (n--)
{
cin >> a;
cout << f(a) << '\n';
}
return 0;
}