#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int mod = 1'000'000'007;

struct Entry {
    int c0;
    int c1;
    int c3;
    int new_c3;

    friend ostream &operator<<(ostream &os, Entry e)
    {
        e.dump(os);
        return os;
    }

    void dump(ostream &os)
    {
        os << "{ " << c0 << ", " << c1 << ", " << c3 << ", " << new_c3 << " }";
    }
};
static Entry dp[2'000'005];
static int dp_ans[2'000'005];

static void precalc()
{
    dp[1].c0 = 1;
    for (int i = 1; i < 2'000'000; ++i) {
        dp[i + 1].c0 = (dp[i].c0 + 2LL * dp[i].c1) % mod;
        dp[i + 1].c1 = dp[i].c0;
        dp[i + 1].c3 = (dp[i].c3 + dp[i].c1) % mod;
        dp[i + 1].new_c3 = dp[i].c1;
        //    cerr << dp[i + 1] << "\n";
    }
}

static int solve(const int n)
{
    if (n <= 2)
        return 0;
    if (n <= 4)
        return 4; // 1 claw with 4 vertices

    auto sum = 0LL;
    for (auto i = n; i >= 0; i -= 3) {
        sum += dp[i].new_c3;
    }
    return (4LL * sum) % mod;
}

int main()
{
    precalc();

    std::ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n; // 2'000'000
        cin >> n;
        cout << solve(n) << "\n";
    }
    return 0;
}


#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int mod = 1'000'000'007;

struct Entry {
    int c0;
    int c1;
    int c3;
    int new_c3;

    friend ostream &operator<<(ostream &os, Entry e)
    {
        e.dump(os);
        return os;
    }

    void dump(ostream &os)
    {
        os << "{ " << c0 << ", " << c1 << ", " << c3 << ", " << new_c3 << " }";
    }
};
static Entry dp[2'000'005];
static int dp_done = 0;

static int solve(const int n)
{
    if (n <= 2)
        return 0;
    if (n <= 4)
        return 4; // 1 claw with 4 vertices

    dp[1].c0 = 1;
    for (int i = max(1, dp_done); i < n; ++i) {
        dp[i + 1].c0 = (dp[i].c0 + 2LL * dp[i].c1) % mod;
        dp[i + 1].c1 = dp[i].c0;
        dp[i + 1].c3 = (dp[i].c3 + dp[i].c1) % mod;
        dp[i + 1].new_c3 = dp[i].c1;
        //    cerr << dp[i + 1] << "\n";
    }
    dp_done = n;

    auto sum = 0LL;
    for (auto i = n; i >= 0; i -= 3) {
        sum += 4LL * dp[i].new_c3 % mod;
        sum %= mod;
    }
    return sum % mod;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n; // 2'000'000
        cin >> n;
        cout << solve(n) << "\n";
    }
    return 0;
}


#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int mod = 1'000'000'007;

struct Entry {
    int c0;
    int c1;
    int c3;
    int new_c3;

    friend ostream &operator<<(ostream &os, Entry e)
    {
        e.dump(os);
        return os;
    }

    void dump(ostream &os)
    {
        os << "{ " << c0 << ", " << c1 << ", " << c3 << ", " << new_c3 << " }";
    }
};
static Entry dp[2'000'005];
static dp_done = 0;

static int solve(const int n)
{
    if (n <= 2)
        return 0;
    if (n <= 4)
        return 4; // 1 claw with 4 vertices

    dp[1].c0 = 1;
    for (int i = max(1, dp_done); i < n; ++i) {
        dp[i + 1].c0 = (dp[i].c0 + 2LL * dp[i].c1) % mod;
        dp[i + 1].c1 = dp[i].c0;
        dp[i + 1].c3 = (dp[i].c3 + dp[i].c1) % mod;
        dp[i + 1].new_c3 = dp[i].c1;
        //    cerr << dp[i + 1] << "\n";
    }
    dp_done = n;

    auto sum = 0LL;
    for (auto i = n; i >= 0; i -= 3) {
        sum += 4LL * dp[i].new_c3 % mod;
        sum %= mod;
    }
    return sum % mod;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n; // 2'000'000
        cin >> n;
        cout << solve(n) << "\n";
    }
    return 0;
}


#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int mod = 1'000'000'007;

struct Entry {
    int c0;
    int c1;
    int c3;
    int new_c3;

    friend ostream &operator<<(ostream &os, Entry e)
    {
        e.dump(os);
        return os;
    }

    void dump(ostream &os)
    {
        os << "{ " << c0 << ", " << c1 << ", " << c3 << ", " << new_c3 << " }";
    }
};
static Entry dp[2'000'005];

static int solve(const int n)
{
    if (n <= 2)
        return 0;
    if (n <= 4)
        return 4; // 1 claw with 4 vertices

    dp[1].c0 = 1;
    for (int i = 1; i < n; ++i) {
        dp[i + 1].c0 = (dp[i].c0 + 2LL * dp[i].c1) % mod;
        dp[i + 1].c1 = dp[i].c0;
        dp[i + 1].c3 = (dp[i].c3 + dp[i].c1) % mod;
        dp[i + 1].new_c3 = dp[i].c1;

        //    cerr << dp[i + 1] << "\n";
    }

    auto sum = 0LL;
    for (auto i = n; i >= 0; i -= 3) {
        sum += 4LL * dp[i].new_c3 % mod;
        sum %= mod;
    }
    return sum % mod;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n; // 2'000'000
        cin >> n;
        cout << solve(n) << "\n";

        for (auto i = 0; i <= n; ++i)
            dp[i] = {};
    }
    return 0;
}


#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int mod = 1'000'000'007;

struct Entry {
    int c0;
    int c1;
    int c3;
    int new_c3;

    friend ostream &operator<<(ostream &os, Entry e)
    {
        e.dump(os);
        return os;
    }

    void dump(ostream &os)
    {
        os << "{ " << c0 << ", " << c1 << ", " << c3 << ", " << new_c3 << " }";
    }
};
static Entry dp[2'000'005];
static large dp_ans[2'000'005];

static void precalc()
{
    dp[1].c0 = 1;
    for (int i = 1; i < 2'000'000; ++i) {
        dp[i + 1].c0 = (dp[i].c0 + 2LL * dp[i].c1) % mod;
        dp[i + 1].c1 = dp[i].c0;
        dp[i + 1].c3 = (dp[i].c3 + dp[i].c1) % mod;
        dp[i + 1].new_c3 = dp[i].c1;
        //    cerr << dp[i + 1] << "\n";
    }

    dp_ans[0] = dp[0].new_c3;
    dp_ans[1] = dp[1].new_c3;
    dp_ans[2] = dp[2].new_c3;

    large ans[3] = {dp_ans[0], dp_ans[1], dp_ans[2]};

    for (int i = 3; i <= 2'000'000; ++i) {
        ans[i % 3] += dp[i].new_c3;
        dp_ans[i] = ans[i % 3];
    }
}

static int solve(const int n)
{
    if (n <= 2)
        return 0;
    if (n <= 4)
        return 4; // 1 claw with 4 vertices

    return dp_ans[n] * 4 % mod;
}

int main()
{
    precalc();

    std::ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n; // 2'000'000
        cin >> n;
        cout << solve(n) << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int maxn = 200005;
    int claws[maxn];
    int leaves[maxn];
    int trigger[maxn];
    for (int i = 0; i < maxn; i++) {
        claws[i] = 0;
        leaves[i] = 0;
        trigger[i] = 0;
    }
    leaves[1] = 1;
    int mod = 3*(1e9+7);
    for (int i = 1; i < maxn; i++) {
        leaves[i+1] += leaves[i];
        leaves[i+1] += 2*trigger[i];
        claws[i+1] += trigger[i];
        //claws[i+1] += claws[i];
        trigger[i+1] += leaves[i];

        leaves[i+1] %= mod;
        claws[i+1] %= mod;
        trigger[i+1] %= mod;
    }

    /*for (int i = 1; i < maxn; i++) {
        cout << i << endl;
        cout << "leaves: " << leaves[i] << " claws: " << claws[i] << " trigger: " << trigger[i] << '\n';
    }*/
    int t;
    cin >> t;

    int psum[maxn];
    for (int i = 0; i < maxn; i++) psum[i] = 0;
    for (int i = 3; i < maxn; i++) {
        psum[i] = claws[i]*4 + psum[i-3];
        psum[i] %= (int)(1e9+7);
    }

    while (t--) {
        int i;
        cin >> i;
        int res = psum[i];
        res %= (int)(1e9+7);
        while (res < 0) res += 1e9+7;
        cout << res << '\n';
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    set<int> s;
    map<int,int> m;

    vector<int> v;
    int t;
    cin >> t;
    int nt = t;
    while (t--) {
        int x;
        cin >> x;
        v.push_back(x);
        s.emplace(x);
    }

    int maxn = 210005;
    int oclaws = 0;
    int oleaves = 1;
    int otrigger = 0;
    int mod = 3*(1e9+7);

    queue<int> q;
    for (int i = 0; i < 3; i++) q.emplace(0);

    for (int i = 3; i < maxn; i++) {
        int leaves = 0;
        int claws = 0;
        int trigger = 0;

        leaves += oleaves;
        leaves += 2*otrigger;
        claws += otrigger;
        //claws[i+1] += claws[i];
        trigger += oleaves;

        leaves %= mod;
        claws %= mod;
        trigger %= mod;

        oleaves = leaves;
        otrigger = trigger;
        oclaws = claws;

        int res = q.front() + claws*4;
        q.pop();
        if (s.count(i) > 0) {
            m[i] = res;
        }
        q.emplace(res);
    }

    for (int i = 0; i < nt; i++) {
        if (i < 3) cout << "0\n";
        else
        cout << m[v[i]]%(int)(1e9+7) << '\n';
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int maxn = 2000005;
    int claws[maxn];
    int leaves[maxn];
    int trigger[maxn];
    for (int i = 0; i < maxn; i++) {
        claws[i] = 0;
        leaves[i] = 0;
        trigger[i] = 0;
    }
    leaves[1] = 1;
    int mod = 3*(1e9+7);
    for (int i = 1; i < maxn; i++) {
        leaves[i+1] += leaves[i];
        leaves[i+1] += 2*trigger[i];
        claws[i+1] += trigger[i];
        //claws[i+1] += claws[i];
        trigger[i+1] += leaves[i];

        leaves[i+1] %= mod;
        claws[i+1] %= mod;
        trigger[i+1] %= mod;
    }

    /*for (int i = 1; i < maxn; i++) {
        cout << i << endl;
        cout << "leaves: " << leaves[i] << " claws: " << claws[i] << " trigger: " << trigger[i] << '\n';
    }*/
    int t;
    cin >> t;

    int psum[maxn];
    for (int i = 0; i < maxn; i++) psum[i] = 0;
    for (int i = 3; i < maxn; i++) {
        psum[i] = claws[i]*4 + psum[i-3];
        psum[i] %= (int)(1e9+7);
    }

    while (t--) {
        int i;
        cin >> i;
        int res = psum[i];
        res %= (int)(1e9+7);
        while (res < 0) res += 1e9+7;
        cout << res << '\n';
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    set<int> s;
    map<int,int> m;

    vector<int> v;
    int t;
    cin >> t;
    int nt = t;
    while (t--) {
        int x;
        cin >> x;
        v.push_back(x);
        s.emplace(x);
        cout << " got " << x << '\n';
    }

    int maxn = 210005;
    int oclaws = 0;
    int oleaves = 1;
    int otrigger = 0;
    int mod = 3*(1e9+7);

    queue<int> q;
    for (int i = 0; i < 3; i++) q.emplace(0);

    cout << " hello\n";

    for (int i = 3; i < maxn; i++) {
        int leaves = 0;
        int claws = 0;
        int trigger = 0;

        leaves += oleaves;
        leaves += 2*otrigger;
        claws += otrigger;
        //claws[i+1] += claws[i];
        trigger += oleaves;

        leaves %= mod;
        claws %= mod;
        trigger %= mod;

        oleaves = leaves;
        otrigger = trigger;
        oclaws = claws;

        int res = q.front() + claws*4;
        q.pop();
        if (s.count(i) > 0) {
            m[i] = res;
        }
        q.emplace(res);
    }

    for (int i = 0; i < nt; i++) {
        if (i < 3) cout << "0\n";
        else
        cout << m[v[i]]%(int)(1e9+7) << '\n';
    }
}
/*

 */


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MAX = 5e6+10, MOD = 1e9+7;

ll ans[MAX];

int main() { _
	ans[0] = ans[1] = 0;
	for (int i = 3; i < MAX; i++)
		ans[i] = (ans[i-1] + 2*ans[i-2] + 4*(i%3==0))%MOD;
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		cout << ans[n] << endl;
	}
	exit(0);
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MOD = 1e9+7;

#define MODULAR true
template<typename T> struct matrix : vector<vector<T>> {
	int n, m;

	void print() {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) cout << (*this)[i][j] << " ";
			cout << endl;
		}
	}

	matrix(int n_, int m_, bool ident = false) :
			vector<vector<T>>(n_, vector<T>(m_, 0)), n(n_), m(m_) {
		if (ident) {
			assert(n == m);
			for (int i = 0; i < n; i++) (*this)[i][i] = 1;
		}
	}
	matrix(const vector<vector<T>>& c) : vector<vector<T>>(c),
		n(c.size()), m(c[0].size()) {}
	matrix<T> operator+(matrix<T>& r) {
		matrix<T> M(n, m, 0);
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
			M[i][j] = (*this)[i][j] + r[i][j];
#if MODULAR
			if (M[i][j] >= MOD) M[i][j] -= MOD;
#endif
		}
		return M;
	}
	matrix<T> operator*(matrix<T>& r) {
		assert(m == r.n);
		matrix<T> M(n, r.m, 0);
		for (int i = 0; i < n; i++) for (int k = 0; k < m; k++)
			for (int j = 0; j < r.m; j++) {
				T add = (*this)[i][k] * r[k][j];
#if MODULAR
				M[i][j] += add%MOD;
				if (M[i][j] >= MOD) M[i][j] -= MOD;
#else
				M[i][j] += add;
#endif
			}
		return M;
	}
	matrix<T> operator^(ll e){
		assert(n == m);
		matrix<T> M(n, n, true);
		matrix<T> at = *this;
		while (e) {
			if (e&1) M = M*at;
			e >>= 1;
			at = at*at;
		}
		return M;
	}
	void apply_transform(matrix M, ll e){
		auto& v = *this;
		while (e) {
			if (e&1) v = M*v;
			e >>= 1;
			M = M*M;
		}
	}
};

int main() { _
	int t;
	cin >> t;
	matrix<ll> m({
		{5, 6, 0, 3},
		{3, 2, 0, 1},
		{1, 2, 0, 1},
		{0, 0, 0, 1}
	});
	matrix<ll> v({
		{0},
		{0},
		{0},
		{4}
	});
	while (t--){
		int n;
		cin >> n;

		auto v2 = v;
		v2.apply_transform(m, n/3);
		cout << v2[2-(n%3)][0] << endl;
	}
	exit(0);
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

const int MOD = 1e9+7;

#define MODULAR true
template<typename T> struct matrix : vector<vector<T>> {
	int n, m;

	void print() {
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
			cout << (*this)[i][j] << " \n"[j==m-1];
	}

	matrix(int n_, int m_, bool ident = false) :
			vector<vector<T>>(n_, vector<T>(m_, 0)), n(n_), m(m_) {
		if (ident) {
			assert(n == m);
			for (int i = 0; i < n; i++) (*this)[i][i] = 1;
		}
	}
	matrix(const vector<vector<T>>& c) : vector<vector<T>>(c),
		n(c.size()), m(c[0].size()) {}
	matrix<T> operator*(matrix<T>& r) {
		assert(m == r.n);
		matrix<T> M(n, r.m, 0);
		for (int i = 0; i < n; i++) for (int k = 0; k < m; k++)
			for (int j = 0; j < r.m; j++) {
				T add = (*this)[i][k] * r[k][j];
#if MODULAR
				M[i][j] += add%MOD;
				if (M[i][j] >= MOD) M[i][j] -= MOD;
#else
				M[i][j] += add;
#endif
			}
		return M;
	}
	matrix<T> operator^(ll e){
		assert(n == m);
		matrix<T> M(n, n, true), at = *this;
		while (e) {
			if (e&1) M = M*at;
			e >>= 1;
			at = at*at;
		}
		return M;
	}
};

int main(){ _
	int t;
	cin >> t;
	matrix<ll> m({
		{5, 6, 0, 3},
		{3, 2, 0, 1},
		{1, 2, 0, 1},
		{0, 0, 0, 1}
	});
	matrix<ll> init({
		{0},
		{0},
		{0},
		{4}
	});
	while (t--){
		int n;
		cin >> n;

		auto M = m^(n/3);
		auto v = M*init;
		cout << v[2-(n%3)][0] << endl;
	}
	exit(0);
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

const ll MOD = 1e9+7;

template<int p> struct mod_int {
	ll pow(ll b, ll e) {
		if (e == 0) return 1;
		ll r = pow(b*b%p, e/2);
		if (e%2 == 1) r = (r*b)%p;
		return r;
	}
	ll inv(ll b) { return pow(b, p-2); }

	using m = mod_int;
	int v;
	mod_int() {}
	mod_int(ll v_) {
		if (v_ >= p || v_ <= -p) v_ %= p;
		if (v_ < 0) v_ += p;
		v = v_;
	}
	m& operator+=(const m &a) {
		v += a.v;
		if (v >= p) v -= p;
		return *this;
	}
	m& operator-=(const m &a) {
		v -= a.v;
		if (v < 0) v += p;
		return *this;
	}
	m& operator*=(const m &a) {
		v = (v*ll(a.v))%p;
		return *this;
	}
	m& operator/=(const m &a) {
		v = (v*inv(a.v))%p;
		return *this;
	}
	m operator-(){ return m(-v); }
	m& operator^=(ll e) {
		if (e < 0){
			v = inv(v);
			e = -e;
		}
		v = pow(v, e%(p-1));
		return *this;
	}
	bool operator==(const m &a) { return v == a.v; }
	bool operator!=(const m &a) { return v != a.v; }
	friend istream &operator>>(istream &in, m& a) {
		ll val; in >> val;
		a = m(val);
		return in;
	}
	friend ostream &operator<<(ostream &out, m a) {
		return out << a.v;
	}
	friend m operator+(m a, m b) { return a+=b; }
	friend m operator-(m a, m b) { return a-=b; }
	friend m operator*(m a, m b) { return a*=b; }
	friend m operator/(m a, m b) { return a/=b; }
	friend m operator^(m a, ll e) { return a^=e; }
};

using mint = mod_int<MOD>;

template<typename T> struct matrix : vector<vector<T>> {
	int n, m;

	matrix(int n_, int m_, bool ident = false) :
		vector<vector<T>>(n_, vector<T>(m_, 0)), n(n_), m(m_) {
			if (ident) {
				assert(n == m);
				for (int i = 0; i < n; i++) (*this)[i][i] = 1;
			}
		}
	matrix(initializer_list<initializer_list<T>> c)
		:matrix(c.size(), (*c.begin()).size()){
			int i, j;
			i = 0;
			for (auto &it : c){
				j = 0;
				for (auto &jt : it){
					this->at(i)[j] = jt;
					j++;
				}
				i++;
			}
		}

	matrix<T> operator*(matrix<T>& r) {
		matrix<T> M(n, r.m, 0);
		for (int i = 0; i < n; i++) for (int k = 0; k < m; k++)
			for (int j = 0; j < r.m; j++)
				M[i][j] += (*this)[i][k] * r[k][j];
		return M;
	}
	matrix<T> operator^(ll e){
		matrix<T> M(n, n, true), at = *this;
		while (e) {
			if (e&1) M = M*at;
			e >>= 1;
			at = at*at;
		}
		return M;
	}
};

using matrixm = matrix<mint>;

int main(){ _
	int t;
	cin >> t;
	matrixm m = {
		{5, 6, 0, 3},
		{3, 2, 0, 1},
		{1, 2, 0, 1},
		{0, 0, 0, 1}
	};
	matrixm init = {
		{0},
		{0},
		{0},
		{4}
	};
	while (t--){
		int n;
		cin >> n;

		matrixm M = m^(n/3);
		matrixm v = M*init;
		cout << v[2-(n%3)][0] << endl;
	}
	exit(0);
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MAX = 2e6+10, MOD = 1e9+7;

ll ans[MAX][2];

int main() { _
	ans[1][0] = ans[2][0] = 0;
	ans[1][1] = ans[2][1] = 0;
	for (int i = 3; i < MAX; i++) {
		ans[i][0] = (ans[i-1][1] + 2*ans[i-2][1])%MOD;
		ans[i][1] = (4 + ans[i-1][0] + 2*ans[i-2][0])%MOD;
		ans[i][1] = max(ans[i][1], ans[i][0]);
	}
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		cout << ans[n][1] << endl;
	}
	exit(0);
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MOD = 1e9+7;

#define MODULAR true
template<typename T> struct matrix : vector<vector<T>> {
	int n, m;

	void print() {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) cout << (*this)[i][j] << " ";
			cout << endl;
		}
	}

	matrix(int n_, int m_, bool ident = false) :
			vector<vector<T>>(n_, vector<T>(m_, 0)), n(n_), m(m_) {
		if (ident) {
			assert(n == m);
			for (int i = 0; i < n; i++) (*this)[i][i] = 1;
		}
	}
	matrix(const vector<vector<T>>& c) : vector<vector<T>>(c),
		n(c.size()), m(c[0].size()) {}
	matrix<T> operator*(matrix<T>& r) {
		assert(m == r.n);
		matrix<T> M(n, r.m, 0);
		for (int i = 0; i < n; i++) for (int k = 0; k < m; k++)
			for (int j = 0; j < r.m; j++) {
				T add = (*this)[i][k] * r[k][j];
#if MODULAR
				M[i][j] += add%MOD;
				if (M[i][j] >= MOD) M[i][j] -= MOD;
#else
				M[i][j] += add;
#endif
			}
		return M;
	}
	matrix<T> operator^(ll e){
		assert(n == m);
		matrix<T> M(n, n, true);
		matrix<T> at = *this;
		while (e) {
			if (e&1) M = M*at;
			e >>= 1;
			at = at*at;
		}
		return M;
	}
	void apply_transform(matrix M, ll e){
		auto& v = *this;
		while (e) {
			if (e&1) v = M*v;
			e >>= 1;
			M = M*M;
		}
	}
};

int main() { _
	int t;
	cin >> t;
	matrix<ll> m({
		{5, 6, 0, 3},
		{3, 2, 0, 1},
		{1, 2, 0, 1},
		{0, 0, 0, 1}
	});
	matrix<ll> v({
		{0},
		{0},
		{0},
		{4}
	});
	while (t--){
		int n;
		cin >> n;

		auto v2 = v;
		v2.apply_transform(m, n/3);
		cout << v2[2-(n%3)][0] << endl;
	}
	exit(0);
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

template<int p> struct mod_int {
	ll pow(ll b, ll e) {
		if (e == 0) return 1;
		ll r = pow(b*b%p, e/2);
		if (e%2 == 1) r = (r*b)%p;
		return r;
	}
	ll inv(ll b) { return pow(b, p-2); }

	using m = mod_int;
	int v;
	mod_int() {}
	mod_int(ll v_) {
		if (v_ >= p || v_ <= -p) v_ %= p;
		if (v_ < 0) v_ += p;
		v = v_;
	}
	m& operator+=(const m &a) {
		v += a.v;
		if (v >= p) v -= p;
		return *this;
	}
	m& operator-=(const m &a) {
		v -= a.v;
		if (v < 0) v += p;
		return *this;
	}
	m& operator*=(const m &a) {
		v = (v*ll(a.v))%p;
		return *this;
	}
	m& operator/=(const m &a) {
		v = (v*inv(a.v))%p;
		return *this;
	}
	m operator-(){ return m(-v); }
	m& operator^=(ll e) {
		if (e < 0){
			v = inv(v);
			e = -e;
		}
		v = pow(v, e%(p-1));
		return *this;
	}
	bool operator==(const m &a) { return v == a.v; }
	bool operator!=(const m &a) { return v != a.v; }
	friend istream &operator>>(istream &in, m& a) {
		ll val; in >> val;
		a = m(val);
		return in;
	}
	friend ostream &operator<<(ostream &out, m a) {
		return out << a.v;
	}
	friend m operator+(m a, m b) { return a+=b; }
	friend m operator-(m a, m b) { return a-=b; }
	friend m operator*(m a, m b) { return a*=b; }
	friend m operator/(m a, m b) { return a/=b; }
	friend m operator^(m a, ll e) { return a^=e; }
};

typedef mod_int<(int)1e9+7> mint;

#define MODULAR false
template<typename T> struct matrix : vector<vector<T>> {
	int n, m;

	void print() {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) cout << (*this)[i][j] << " ";
			cout << endl;
		}
	}

	matrix(int n_, int m_, bool ident = false) :
			vector<vector<T>>(n_, vector<T>(m_, 0)), n(n_), m(m_) {
		if (ident) {
			assert(n == m);
			for (int i = 0; i < n; i++) (*this)[i][i] = 1;
		}
	}
	matrix(const vector<vector<T>>& c) : vector<vector<T>>(c),
		n(c.size()), m(c[0].size()) {}
	matrix<T> operator+(matrix<T>& r) {
		matrix<T> M(n, m, 0);
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
			M[i][j] = (*this)[i][j] + r[i][j];
#if MODULAR
			if (M[i][j] >= MOD) M[i][j] -= MOD;
#endif
		}
		return M;
	}
	matrix<T> operator*(matrix<T>& r) {
		assert(m == r.n);
		matrix<T> M(n, r.m, 0);
		for (int i = 0; i < n; i++) for (int k = 0; k < m; k++)
			for (int j = 0; j < r.m; j++) {
				T add = (*this)[i][k] * r[k][j];
#if MODULAR
				M[i][j] += add%MOD;
				if (M[i][j] >= MOD) M[i][j] -= MOD;
#else
				M[i][j] += add;
#endif
			}
		return M;
	}
	matrix<T> operator^(ll e){
		assert(n == m);
		matrix<T> M(n, n, true);
		matrix<T> at = *this;
		while (e) {
			if (e&1) M = M*at;
			e >>= 1;
			at = at*at;
		}
		return M;
	}
	void apply_transform(matrix M, ll e){
		auto& v = *this;
		while (e) {
			if (e&1) v = M*v;
			e >>= 1;
			M = M*M;
		}
	}
};

int main() { _
	int t;
	cin >> t;
	matrix<mint> m({
		{5, 6, 0, 3},
		{3, 2, 0, 1},
		{1, 2, 0, 1},
		{0, 0, 0, 1}
	});
	matrix<mint> v({
		{0},
		{0},
		{0},
		{4}
	});
	while (t--){
		int n;
		cin >> n;

		auto v2 = v;
		v2.apply_transform(m, n/3);
		cout << v2[2-(n%3)][0] << endl;
	}
	exit(0);
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve()
{
 int n=2000000;
int a[n+1];
a[1]=0;
a[2]=0;
a[3]=4;
rep(i,4,n+1)
{
    a[i]=(a[i-1]+(2*a[i-2])%hell)%hell;
    if(i%3==0)
        a[i]=(a[i]+4)%hell;
}
ip(t);
while(t--)
{

    ip(k);
    cout<<a[k]%hell<<"\n";
}

}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int t=1;
   //cin>>t;
    while(t--)  {solve();
    cout<<"\n";
   }
    return 0;
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve(){
//ip(n);
//int ans=0;
//int a[n+1][3];
//a[1][0]=1;
//a[1][1]=0;
//a[1][2]=0;
//rep(i,2,n+1)
//{
//    a[i][0]=(a[i-1][0]+2*a[i-1][1])%hell;
//    a[i][1]=a[i-1][0];
//    a[i][2]=a[i-1][1];
//}
int ar[20001][2];
int a,b,c;
a=0;
b=0;
 c=0;
rep(i,3,2000001)
{a=b;
    b=c;

    c=(b+(2*a)%hell)%hell;
    if(i%3==0)
        c=(c+4)%hell;

        if(i%100==0)
        {

            ar[i/100][0]=c;
            ar[i/100][1]=b;

        }

}
ip(t)
while(t--)
{ip(n);
int index=n/100;
int cc=ar[index][0];
int bb=ar[index][1];
int aa;
for(int j=index*100+1;j<=n;j++)
{
  aa=bb;
    bb=cc;

    cc=(bb+(2*aa)%hell)%hell;
    if(j%3==0)
        cc=(cc+4)%hell;
}
cout<<cc<<"\n";
}

}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
   //cin>>t;
    while(t--)  {solve();
    cout<<"\n";
   }
    return 0;
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve()
{
 int n=2000000;
int a[n+1];
a[1]=0;
a[2]=0;
a[3]=4;
rep(i,4,n+1)
{
    a[i]=(a[i-1]+(2*a[i-2])%hell)%hell;
    if(i%3==0)
        a[i]=(a[i]+4)%hell;
}
ip(t);
while(t--)
{

    ip(k);
    cout<<a[k]%hell;
}

}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int t=1;
   //cin>>t;
    while(t--)  {solve();
    cout<<"\n";
   }
    return 0;
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve(){
ip(n);
//int ans=0;
//int a[n+1][3];
//a[1][0]=1;
//a[1][1]=0;
//a[1][2]=0;
//rep(i,2,n+1)
//{
//    a[i][0]=(a[i-1][0]+2*a[i-1][1])%hell;
//    a[i][1]=a[i-1][0];
//    a[i][2]=a[i-1][1];
//}
int a[n+1];
a[1]=0;
a[2]=0;
a[3]=4;
rep(i,4,n+1)
{
    a[i]=(a[i-1]+(2*a[i-2])%hell)%hell;
    if(i%3==0)
        a[i]=(a[i]+4)%hell;
}
cout<<a[n]%hell;
}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
   cin>>t;
    while(t--)  {solve();
    cout<<"\n";
   }
    return 0;
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve(int a[])
{

    ip(k);
    cout<<a[k]%hell;

}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n=2000000;
int a[n+1];
a[1]=0;
a[2]=0;
a[3]=4;
rep(i,4,n+1)
{
    a[i]=(a[i-1]+(2*a[i-2])%hell)%hell;
    if(i%3==0)
        a[i]=(a[i]+4)%hell;
}
    int t=1;
   cin>>t;
    while(t--)  {solve(a);
    cout<<"\n";
   }
    return 0;
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve(ll dp[][2000000]){
ll n;
cin>>n;
cout<<(4*dp[2][n-1])%hell<<endl;
}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll test;
    //test=1;
    ll dp[3][2000000];
dp[0][0]=1;
dp[1][0]=0;
dp[2][0]=0;
rep(i,1,2000000){
    dp[0][i]=(2*dp[1][i-1]+dp[0][i-1])%hell;
    dp[1][i]=dp[0][i-1];
    ll k=max((ll)0,i-3);
    dp[2][i]=(dp[2][k]+dp[1][i-1])%hell;
}
    cin>>test;
    while(test--)
    {
        solve(dp);
    }
    return 0;
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve(){
ip(n);
//int ans=0;
//int a[n+1][3];
//a[1][0]=1;
//a[1][1]=0;
//a[1][2]=0;
//rep(i,2,n+1)
//{
//    a[i][0]=(a[i-1][0]+2*a[i-1][1])%hell;
//    a[i][1]=a[i-1][0];
//    a[i][2]=a[i-1][1];
//}

int a,b,c;
a=0;
b=0;
 c=0;
rep(i,3,n+1)
{a=b;
    b=c;

    c=(b+(2*a)%hell)%hell;
    if(i%3==0)
        c=(c+4)%hell;
}
cout<<c%hell;
}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
   cin>>t;
    while(t--)  {solve();
    cout<<"\n";
   }
    return 0;
}


#include<bits/stdc++.h>
#define int         long long
#define ip(x)        int x; cin>>x;
#define aray(a,n)    int a[n]; rep(i,0,n){cin>>a[i];}
#define ll 			long long
#define MaX(a,n)    *max_element(a,a + n)
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
int mod=1000000007;
void normalize(int &a){a=(a+mod)%mod;}
int modmul(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a*b)%mod;}
int modadd(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a+b)%mod;}
int modsub(int a,int b){a=a%mod;b=b%mod;normalize(a);normalize(b);return (a-b+mod)%mod;}
int me(int x,int n){x%=mod;if(n==0)return 1;int u=me(x,n/2)%mod;u=(u*u)%mod;if(n%2)u=(u*x)%mod;return u;}
int ipow(int a,int b){int c=1; while(b--) c*=a; return c; }
int logb(int a,int b){int ans=0; while(a>=b) { a/=b; ans++; } return ans;}
int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); }
int lcm(int a,int b){return (a/gcd(a,b))*b;}
bool isprime(int n){for(int i=2;i*i<=n;i++){if(n%i==0){ return false;}}if(n==1)return false; return true;}
using namespace std;
int a[200005];

void solve(){
//ip(n);
//int ans=0;
//int a[n+1][3];
//a[1][0]=1;
//a[1][1]=0;
//a[1][2]=0;
//rep(i,2,n+1)
//{
//    a[i][0]=(a[i-1][0]+2*a[i-1][1])%hell;
//    a[i][1]=a[i-1][0];
//    a[i][2]=a[i-1][1];
//}
int n=2000000;
int a[n+1];
a[1]=0;
a[2]=0;
a[3]=4;
rep(i,4,n+1)
{
    a[i]=(a[i-1]+(2*a[i-2])%hell)%hell;
    if(i%3==0)
        a[i]=(a[i]+4)%hell;
}
ip(t);
while(t--)
{
    ip(k);
    cout<<a[k]%hell;
}

}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
   //cin>>t;
    while(t--)  {solve();
    cout<<"\n";
   }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#ifndef KATARA
#define deb(...) ;
#endif
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
const int MOD = 1e9 + 7;

void solve(){

   int n ;
   cin >> n;

   if(n < 3) {cout << 0 << endl; return;}
   if(n <= 4) {cout << 4 << endl; return;}
   vi dp(n + 10 , 0);
   dp[0] = dp[1] = dp[2] = 0;
   deb(n )
   dp[3] = 1;

   dp[4] = 1;

   fr(i , 5 , n + 1) {dp[i] = 2 * dp[i -2] + dp[i - 1] +( i % 3 == 0); dp[i] %= MOD;}

   cout << (dp[n] * 4 ) % MOD << endl;

}

signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#ifndef KATARA
#define deb(...) ;
#endif
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
     int dp[2000006];

    fill(dp, 0);

   dp[0] = dp[1] = dp[2] = 0;
   dp[3] = 1;

   dp[4] = 1;

   for(int i = 3 ; i <= 2000005; i++){
       dp[i] = 2 * dp[i - 2] + dp[i - 1] + (i % 3 == 0);
       dp[i] %= MOD;
   }

    int t;
    cin>>t;
    while(t--){
        int n;
       cin>>n;
       cout<<(4*dp[n])%MOD<<endl;
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#ifndef KATARA
#define deb(...) ;
#endif
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
     int dp[2000006];

    fill(dp, 0);

   dp[0] = dp[1] = dp[2] = 0;
   dp[3] = 1;

   dp[4] = 1;

   for(int i = 3 ; i <= 2000005; i++){
       dp[i] = 2 * dp[i - 2] + dp[i - 1] + (i % 3 == 0);
       dp[i] %= MOD;
   }

    int t;
    cin>>t;
    while(t--){
        int n;
        cin >> n;
        int val = (dp[n]);
        val *= 4;
        val = val % MOD;
        if(val < 0) val = (val + MOD) % MOD;
        cout << (val) << endl;
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;
#define vi vector<int>
#define int long long
#ifndef KATARA
#define deb(...) ;
#endif
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)

int go (vi &arr , vi &val){

    int n = arr.size();
    int l = 0 , r = n - 1;

    int curr = 0;
    int ans = 0;

    while(val[curr] == 1){
            ans += 2 * arr[r];
            --r;
            ++curr;
            continue;
    }

    sort(all(val));
    reverse(all(val));
    curr = 0;
    while(curr < val.size()){

       if(val[curr] == 1) break;
        ans += arr[r];
        int tms = val[curr] - 1;

        ans += arr[l];

        l += tms;
        r--;
        ++curr;

    }

    return ans;

}

void solve(){

   int n , k;
   cin >> n >> k;

   vi arr(n);

   trav(i , arr) cin >> i;

   vi val(k);

   trav(i , val) cin >> i;

   sort(all(arr));

   sort(all(val));

   cout << go(arr , val) << endl;

}

signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#ifndef KATARA
#define deb(...) ;
#endif
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
const int MOD = 1e9 + 7;

vi dp(2e5 + 10 , 0);

void solve(){

   int n =  2e5 + 10;

   dp[0] = dp[1] = dp[2] = 0;
   deb(n )
   dp[3] = 1;

   dp[4] = 1;

   fr(i , 5 , n - 1) {dp[i] = 2 * dp[i -2] + dp[i - 1] +( i % 3 == 0); dp[i] %= MOD;}

}

signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
    solve();
    int t=1;
    cin>>t;
    while(t--){
        int n;
        cin >> n;
        cout << (dp[n] * 4 ) % MOD << endl;}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#ifndef KATARA
#define deb(...) ;
#endif
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
const int MOD = 1e9 + 7;

vi dp(2e5 + 10 , 0);

void solve(){

   int n =  2e5 + 10;

   if(n < 3) {cout << 0 << endl; return;}
   if(n <= 4) {cout << 4 << endl; return;}

   dp[0] = dp[1] = dp[2] = 0;
   deb(n )
   dp[3] = 1;

   dp[4] = 1;

   fr(i , 5 , n ) {dp[i] = 2 * dp[i -2] + dp[i - 1] +( i % 3 == 0); dp[i] %= MOD;}

}

signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
    solve();
    int t=1;
    cin>>t;
    while(t--){
        int n;
        cin >> n;
        cout << (dp[n] * 4 ) % MOD << endl;}
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007 //998244353
#define pb push_back
#define endd '\n'
#define inf 1000000000000000000
#define ll long long
#define mk make_pair
#define fi first
#define all(a) a.begin(),a.end()
#define test ll int t,o;cin>>o;for(t=1;t<=o;t++)
#define goog(q,aao) cout<<"Case #"<<q<<": "<<aao<<'\n'
#define co(a) cout<<a<<'\n'
#define coo(a,b) cout<<a<<" "<<b<<'\n'
#define cooo(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define take_arr ll i,j,k,n;mul_itr;set_itr;cin>>n;ll arr[n];loop(i,n)cin>>arr[i]
#define take ll i,j,k,n;mul_itr;set_itr;cin>>n
#define print(arr,n) for(ll w=0;w<n;w++)cout<<arr[w]<<" ";cout<<'\n'
#define print_dou(arr,n,m) for(ll w=0;w<n;w++){ for(ll o=0;o<m;o++){cout<<arr[w][o]<<" "; }cout<<endd;}
#define dis(w) loop(i,w.size())cout<<w[i]<<" ";cout<<'\n'
#define mem(b,q)  memset(b,q , sizeof(b))
#define set_itr set<ll>:: iterator sitr ,sit
#define mul_itr multiset<ll>:: iterator itr,it
#define map_itr map<ll,ll>:: iterator mitr,mit
#define se second
#define pii pair<int,int>
#define iterate(s,d) for(d=s.begin();d!=s.end();++d)
#define pll pair<long long,long long>
#define vll vector<ll>
#define vpll vector< pair<ll,ll> >
#define vppll vector < pair<ll, pair<ll,ll> > >
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define loop1(i,a,n) for(i=a;i<n; i++)
#define loop(i,n) for( i=0;i<n;i++)
#define loop2(n,m) for(int p=0;p<n;p++)for(int q=0;q<m;q++)
#define loop3(n,m,l) for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<l;k++)
#define checkbit(n, b) ((n >> b) & 1)
#define setbits(x) __builtin_popcount(x)  // returns no of set bits in x
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define prefix_sum(arr,n); for(ll oo=1;oo<n;oo++)arr[oo]+=arr[oo-1];
#define PI 3.14159265358979323846
using namespace std;
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll min3(ll a,ll b,ll c){return min(a,min(b,c));}
ll min4(ll a, ll b, ll c, ll d){return min(min(a,b),min(c,d));}
ll min5(ll a, ll b, ll c,ll d,ll e){return min(min(a,b),min(min(c,d),e));}
ll max3(ll a,ll b,ll c){return max(a,max(b,c));}
ll max4(ll a, ll b, ll c, ll d){return max(max(a,b),max(c,d));}
ll max5(ll a, ll b, ll c,ll d,ll e){return max(max(a,b),max(max(c,d),e));}
ll lcm(ll a, ll b)
{
    ll g=__gcd(a, b);
    return a/g*b;
}
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use it as ordered_set <ll> arr;
/*

	NOTE :
	8 direction movement
	int dx[] = { -1, -1,  0, 1, 1, 1,  0, -1 };
	int dy[] = {  0, -1, -1, -1,  0, 1, 1, 1 };

	plus directions
	int dx[]={1, 0, -1 , 0 };
	ind dy[]={0, 1,  0,  -1};

	knight movement
	int dxK[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
	int dyK[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

	in range l-r (inclusive)
	no of elements which give remainder
	0 = r/3-(l-1)/3
	1 = (r+1)/3-l/3
	2 = (r+2)/3-(l+1)/3

 	in general -> (r+remainder)/k-(l-1+remainder)/k

  maxx=*max_element(a,a+n);
  m=(m-1+n)%n;     move anti-clockwise  beaware : if u use some x instead of one use m=(m-x+ (n/x+1)*n)%n
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  find_by_order() and order_of_key(). The first returns an iterator to the k-th largest element (counting from zero), the second � the number of items in a set that are strictly smaller than our item

  in case of multiple query , if u pass an array as argument make sure u pass its copy oterwise , the original array will change

  	iterate over bits
 	while (bits)
	{
    	if (bits & 1)
		{
    			 // Current bit is set to 1
    	}
		else
		{
        		// Current bit is set to 0
   		}

   		 bits >>= 1;
	}

*/
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // PRECISION;
	test
	{
		ll i,j,k,n;
		cin>>n;
		ll a=0,b=0,c=0, ans=0;
		if(n==1)
		{
			cout<<0<<endd;
		}
		else
		{
			a=1;b=0;c=0;
			ll tot=0;
			ll pre1=0, pre2=0,pre3=0;
			loop(i,n-1)
			{
				ll ta=a,tb=b,tc=c;
				c=b;
				b=a;
				a=(a+tb*2)%mod;
				tot=(c+pre3)%mod;
				pre3=pre2%mod;
				pre2=pre1%mod;
				pre1=tot%mod;
			//	trace4(a,b,c,tot);
			//	trace2(pre2,pre1);

			}
			cout<<(max(tot,pre1)*4)%mod<<endd;
		}
	}

    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007 //998244353
#define pb push_back
#define endd '\n'
#define inf 1000000000000000000
#define ll long long
#define mk make_pair
#define fi first
#define all(a) a.begin(),a.end()
#define test ll int t,o;cin>>o;for(t=1;t<=o;t++)
#define goog(q,aao) cout<<"Case #"<<q<<": "<<aao<<'\n'
#define co(a) cout<<a<<'\n'
#define coo(a,b) cout<<a<<" "<<b<<'\n'
#define cooo(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define take_arr ll i,j,k,n;mul_itr;set_itr;cin>>n;ll arr[n];loop(i,n)cin>>arr[i]
#define take ll i,j,k,n;mul_itr;set_itr;cin>>n
#define print(arr,n) for(ll w=0;w<n;w++)cout<<arr[w]<<" ";cout<<'\n'
#define print_dou(arr,n,m) for(ll w=0;w<n;w++){ for(ll o=0;o<m;o++){cout<<arr[w][o]<<" "; }cout<<endd;}
#define dis(w) loop(i,w.size())cout<<w[i]<<" ";cout<<'\n'
#define mem(b,q)  memset(b,q , sizeof(b))
#define set_itr set<ll>:: iterator sitr ,sit
#define mul_itr multiset<ll>:: iterator itr,it
#define map_itr map<ll,ll>:: iterator mitr,mit
#define se second
#define pii pair<int,int>
#define iterate(s,d) for(d=s.begin();d!=s.end();++d)
#define pll pair<long long,long long>
#define vll vector<ll>
#define vpll vector< pair<ll,ll> >
#define vppll vector < pair<ll, pair<ll,ll> > >
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define loop1(i,a,n) for(i=a;i<n; i++)
#define loop(i,n) for( i=0;i<n;i++)
#define loop2(n,m) for(int p=0;p<n;p++)for(int q=0;q<m;q++)
#define loop3(n,m,l) for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<l;k++)
#define checkbit(n, b) ((n >> b) & 1)
#define setbits(x) __builtin_popcount(x)  // returns no of set bits in x
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define prefix_sum(arr,n); for(ll oo=1;oo<n;oo++)arr[oo]+=arr[oo-1];
#define PI 3.14159265358979323846
using namespace std;
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll min3(ll a,ll b,ll c){return min(a,min(b,c));}
ll min4(ll a, ll b, ll c, ll d){return min(min(a,b),min(c,d));}
ll min5(ll a, ll b, ll c,ll d,ll e){return min(min(a,b),min(min(c,d),e));}
ll max3(ll a,ll b,ll c){return max(a,max(b,c));}
ll max4(ll a, ll b, ll c, ll d){return max(max(a,b),max(c,d));}
ll max5(ll a, ll b, ll c,ll d,ll e){return max(max(a,b),max(max(c,d),e));}
ll lcm(ll a, ll b)
{
    ll g=__gcd(a, b);
    return a/g*b;
}
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use it as ordered_set <ll> arr;
/*

	NOTE :
	8 direction movement
	int dx[] = { -1, -1,  0, 1, 1, 1,  0, -1 };
	int dy[] = {  0, -1, -1, -1,  0, 1, 1, 1 };

	plus directions
	int dx[]={1, 0, -1 , 0 };
	ind dy[]={0, 1,  0,  -1};

	knight movement
	int dxK[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
	int dyK[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

	in range l-r (inclusive)
	no of elements which give remainder
	0 = r/3-(l-1)/3
	1 = (r+1)/3-l/3
	2 = (r+2)/3-(l+1)/3

 	in general -> (r+remainder)/k-(l-1+remainder)/k

  maxx=*max_element(a,a+n);
  m=(m-1+n)%n;     move anti-clockwise  beaware : if u use some x instead of one use m=(m-x+ (n/x+1)*n)%n
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  find_by_order() and order_of_key(). The first returns an iterator to the k-th largest element (counting from zero), the second � the number of items in a set that are strictly smaller than our item

  in case of multiple query , if u pass an array as argument make sure u pass its copy oterwise , the original array will change

  	iterate over bits
 	while (bits)
	{
    	if (bits & 1)
		{
    			 // Current bit is set to 1
    	}
		else
		{
        		// Current bit is set to 0
   		}

   		 bits >>= 1;
	}

*/
ll dp[2000009]={0};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 		  ll i,j,k,n;
    		ll a=1;ll b=0;ll c=0;
    		dp[1]=0;
			ll tot=0;
			ll pre1=0, pre2=0,pre3=0;
			loop(i,2000005)
			{
				ll ta=a,tb=b,tc=c;
				c=b;
				b=a;
				a=(a+tb*2)%mod;
				tot=(c+pre3)%mod;
				pre3=pre2%mod;
				pre2=pre1%mod;
				pre1=tot%mod;
				//trace4(a,b,c,tot);
				dp[i+2]=max(tot,pre1);
				//trace2(pre2,pre1);
			}
   // PRECISION;
	test
	{
		ll i,j,k,n;
		cin>>n;
		cout<<(dp[n]*4)%mod<<endd;
	}

    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007 //998244353
#define pb push_back
#define endd '\n'
#define inf 1000000000000000000
#define ll long long
#define mk make_pair
#define fi first
#define all(a) a.begin(),a.end()
#define test ll int t,o;cin>>o;for(t=1;t<=o;t++)
#define goog(q,aao) cout<<"Case #"<<q<<": "<<aao<<'\n'
#define co(a) cout<<a<<'\n'
#define coo(a,b) cout<<a<<" "<<b<<'\n'
#define cooo(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define take_arr ll i,j,k,n;mul_itr;set_itr;cin>>n;ll arr[n];loop(i,n)cin>>arr[i]
#define take ll i,j,k,n;mul_itr;set_itr;cin>>n
#define print(arr,n) for(ll w=0;w<n;w++)cout<<arr[w]<<" ";cout<<'\n'
#define print_dou(arr,n,m) for(ll w=0;w<n;w++){ for(ll o=0;o<m;o++){cout<<arr[w][o]<<" "; }cout<<endd;}
#define dis(w) loop(i,w.size())cout<<w[i]<<" ";cout<<'\n'
#define mem(b,q)  memset(b,q , sizeof(b))
#define set_itr set<ll>:: iterator sitr ,sit
#define mul_itr multiset<ll>:: iterator itr,it
#define map_itr map<ll,ll>:: iterator mitr,mit
#define se second
#define pii pair<int,int>
#define iterate(s,d) for(d=s.begin();d!=s.end();++d)
#define pll pair<long long,long long>
#define vll vector<ll>
#define vpll vector< pair<ll,ll> >
#define vppll vector < pair<ll, pair<ll,ll> > >
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define loop1(i,a,n) for(i=a;i<n; i++)
#define loop(i,n) for( i=0;i<n;i++)
#define loop2(n,m) for(int p=0;p<n;p++)for(int q=0;q<m;q++)
#define loop3(n,m,l) for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<l;k++)
#define checkbit(n, b) ((n >> b) & 1)
#define setbits(x) __builtin_popcount(x)  // returns no of set bits in x
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define prefix_sum(arr,n); for(ll oo=1;oo<n;oo++)arr[oo]+=arr[oo-1];
#define PI 3.14159265358979323846
using namespace std;
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll min3(ll a,ll b,ll c){return min(a,min(b,c));}
ll min4(ll a, ll b, ll c, ll d){return min(min(a,b),min(c,d));}
ll min5(ll a, ll b, ll c,ll d,ll e){return min(min(a,b),min(min(c,d),e));}
ll max3(ll a,ll b,ll c){return max(a,max(b,c));}
ll max4(ll a, ll b, ll c, ll d){return max(max(a,b),max(c,d));}
ll max5(ll a, ll b, ll c,ll d,ll e){return max(max(a,b),max(max(c,d),e));}
ll lcm(ll a, ll b)
{
    ll g=__gcd(a, b);
    return a/g*b;
}
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use it as ordered_set <ll> arr;
/*

	NOTE :
	8 direction movement
	int dx[] = { -1, -1,  0, 1, 1, 1,  0, -1 };
	int dy[] = {  0, -1, -1, -1,  0, 1, 1, 1 };

	plus directions
	int dx[]={1, 0, -1 , 0 };
	ind dy[]={0, 1,  0,  -1};

	knight movement
	int dxK[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
	int dyK[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

	in range l-r (inclusive)
	no of elements which give remainder
	0 = r/3-(l-1)/3
	1 = (r+1)/3-l/3
	2 = (r+2)/3-(l+1)/3

 	in general -> (r+remainder)/k-(l-1+remainder)/k

  maxx=*max_element(a,a+n);
  m=(m-1+n)%n;     move anti-clockwise  beaware : if u use some x instead of one use m=(m-x+ (n/x+1)*n)%n
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  find_by_order() and order_of_key(). The first returns an iterator to the k-th largest element (counting from zero), the second � the number of items in a set that are strictly smaller than our item

  in case of multiple query , if u pass an array as argument make sure u pass its copy oterwise , the original array will change

  	iterate over bits
 	while (bits)
	{
    	if (bits & 1)
		{
    			 // Current bit is set to 1
    	}
		else
		{
        		// Current bit is set to 0
   		}

   		 bits >>= 1;
	}

*/
ll dp[2000000]={0};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 		  ll i,j,k,n;
    		ll a=1;ll b=0;ll c=0;
    		dp[1]=0;
			ll tot=0;
			ll pre1=0, pre2=0,pre3=0;
			loop(i,2000005)
			{
				ll ta=a,tb=b,tc=c;
				c=b;
				b=a;
				a=(a+tb*2)%mod;
				tot=(c+pre3)%mod;
				pre3=pre2%mod;
				pre2=pre1%mod;
				pre1=tot%mod;
				//trace4(a,b,c,tot);
				dp[i+2]=max(tot,pre1);
				//trace2(pre2,pre1);
			}
   // PRECISION;
	test
	{
		ll i,j,k,n;
		cin>>n;
		cout<<(dp[n]*4)%mod<<endd;
	}

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 999999999999999999
#define endl "\n"
#define MOD 1000000007

void func(){

ll n=2000000+5;
ll a[n]={0};

a[1]=a[2]=0;

for(int i=3;i<=2000000;i++){
  a[i] = ((a[i-2]*2)%MOD + a[i-1]%MOD)%MOD;
  if(i%3==0) a[i]+=4;
}

ll t; cin>>t;

for(int i=0;i<t;i++){
  ll t1; cin>>t1;
  cout<<a[t1]<<endl;
}

}

int main(){
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);

          #ifndef ONLINE_JUDGE
          freopen("input.txt", "r" , stdin);
          freopen("output.txt", "w" , stdout);
          #endif

       ll t=1;
       //cin>>t;
       while(t--)
       func();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>,
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

const long int MOD = 1e9 + 7;

long int solve(long int n){

	long int ans = 0;
	for(long int k = 1; k <= n / 2; k++)
		ans = (ans + (long int)sqrt((n / 2) * (n / 2) - k * k)) % MOD;

	ans = (ans * 4) % MOD;
	return ans;
}

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */

   	long int t;
   	cin>>t;

   	while(t--){
   		long int n;
   		cin>>n;
   		cout<<solve(n)<<endl;
   	}
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
        int n;
        cin>>n;
        string str;
        cin>>str;
        int a=0,b=n-1;
        while(str[a]=='0')
            ++a;
        while(str[b]=='1')
            --b;
        if(a<b)
        {
             string res="";
            for(int k=0; k<a; k++)
                res+=str[k];
            res=res+'0';
            for(int k=b+1; k<n; k++)
                res+=str[k];
            cout<<res<<endl;
        }
        else
        {
           cout<<str<<endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define int long long

#define speed ios::sync_with_stdio(false); cin.tie(0)
#define mod 1000000007

using namespace std;

signed main()
{
	// freopen("input.txt","r",stdin);

    speed;

    int t;
    cin>>t;

    int ans[2000001];

    ans[1] = 0;
    ans[2] = 0;
    ans[3] = 4;

    for(int i=4;i<=2000000;i++)
    {
    	ans[i] = (ans[i-1]%mod + ans[i-2]%mod)%mod;
    	ans[i] = (ans[i]%mod + ans[i-2]%mod)%mod;
    }

    while(t--)
    {
    	int n;
    	cin>>n;

    	cout<<ans[n]<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define maxn 100
#define ll long long
#define pp pair<int, int>
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL);
#define inputfile freopen(input.txt, r, stdin)
#define outputfile freopen(out.txt, w, stdout)
#define int ll
using namespace std;
int32_t main()
{
    int testcase;
    cin >> testcase;
    while (testcase--)
    {
        ll n, m, gifts[maxn], friends[maxn];
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            cin >> gifts[i];
        for (int i = 1; i <= m; i++)
            cin >> friends[i];
        sort(gifts + 1, gifts + 1 + n);
        sort(friends + 1, friends + 1 + m);
        int left = 1, right = n, res = 0;
        for (int i = m; i >= 1; i--)
        {
            res += gifts[right];
            friends[i]--;
            if (friends[i] == 0)
                res += gifts[right];
            else
                res += gifts[left];
            right--;
            left += friends[i];
        }
        cout << res << endl;
    }
}


#include<bits/stdc++.h>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>

const int m=1e9+7;
using namespace std;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int32_t main(){

	FIO();
	int dp[2000001];
	dp[1]=dp[2]=0;

	for(int i=3; i<2000001; i++){
		dp[i]=(2*dp[i-2]+dp[i-1] + (i%3==0?4:0))%m;
	}
	w(t){
		int n;cin>>n;
		cout<<dp[n]<<"\n";

	}

	return 0;

}


#include<bits/stdc++.h>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>

const int m=1e9+7;
using namespace std;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int32_t main(){

	FIO();
	int dp[2000001];
	dp[1]=dp[2]=0;
	dp[3]=4;
	for(int i=4; i<2000001; i++){
		dp[i]=(2*dp[i-2]+dp[i-1])%m;
	}
	w(t){
		int n;cin>>n;
		cout<<(dp[n]*4)%m<<"\n";

	}

	return 0;

}


#include<bits/stdc++.h>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>

const int m=1e9+7;
using namespace std;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int32_t main(){

	FIO();
	int dp[2000001];
	dp[1]=dp[2]=0;
	dp[3]=4;
	for(int i=4; i<2000001; i++){
		dp[i]=(2*dp[i-2]+dp[i-1])%m;
	}
	w(t){
		int n;cin>>n;
		cout<<dp[n]<<"\n";

	}

	return 0;

}


#include<bits/stdc++.h>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>

const int m=1e9+7;
using namespace std;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int32_t main(){

	FIO();
	int dp[2000001];
	dp[1]=dp[2]=0;
	dp[3]=4;
	for(int i=0; i<2000001; i++){
		dp[i]=(2*dp[i-2]+dp[i-1])%m;
	}
	w(t){
		int n;cin>>n;
		cout<<(dp[n]*4)%m<<"\n";

	}

	return 0;

}


#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout << #x << ": " << x << endl
#define debugs  cout<<"ssssss"<<endl
#define debugx  cout<<"xxxxxx"<<endl
#define __count(x) __builtin_popcount(x)
//返回二进制下有多少个1  int范围 后加l是 unsigned long 加ll是 unsigned long long
#define __ctz(x) __builtin_ctz(x)           //返回二进制下末尾有几个零
#define __ffs(x) __builtin_ffs(x)           //返回二进制下最后一个1的位置，从1开始
#define __max_elenment *max_element		   //返回一个数组的最大值,参数是数组的起始位置和结束位置
#define __min_elenment *min_element

using namespace std;
typedef long long ll;
const double pi=acos(-1);
const int maxx=2e6+10;
const int mod=1e9+7;
template<typename T>
inline T read()
{
    T s=0,f=1;
    char ch = getchar();
    while(!isdigit(ch))
    {
        if(ch == '-')
            f=-1;
        ch = getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+ch-48;
        ch = getchar();
    }
    return s*f;
}
#define gi() read<int>()
#define gl() read<ll>()
template<typename T>
inline void print(T x)
{
    if(x<0)
        putchar('-'), x=-x;
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}
int t,n;
ll a[maxx];

int main()
{

    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n<3)
        {
            cout<<0<<endl;
            continue;
        }
        else{
            a[3]=4;
            for(int i=4;i<=n;i++)
            {
                if(i%3==0)
                    a[i]=(a[i-1]+2*a[i-2]+4)%mod;
                else
                    a[i]=(a[i-1]+2*a[i-2])%mod;
            }
            cout<<a[n]<<endl;
        }
   }
   return 0;
}


#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout << #x << ": " << x << endl
#define debugs  cout<<"ssssss"<<endl
#define debugx  cout<<"xxxxxx"<<endl
#define __count(x) __builtin_popcount(x)
//返回二进制下有多少个1  int范围 后加l是 unsigned long 加ll是 unsigned long long
#define __ctz(x) __builtin_ctz(x)           //返回二进制下末尾有几个零
#define __ffs(x) __builtin_ffs(x)           //返回二进制下最后一个1的位置，从1开始
#define __max_elenment *max_element		   //返回一个数组的最大值,参数是数组的起始位置和结束位置
#define __min_elenment *min_element

using namespace std;
typedef long long ll;
const double pi=acos(-1);
const int maxx=2e6+10;
const int mod=1e9+7;
template<typename T>
inline T read()
{
    T s=0,f=1;
    char ch = getchar();
    while(!isdigit(ch))
    {
        if(ch == '-')
            f=-1;
        ch = getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+ch-48;
        ch = getchar();
    }
    return s*f;
}
#define gi() read<int>()
#define gl() read<ll>()
template<typename T>
inline void print(T x)
{
    if(x<0)
        putchar('-'), x=-x;
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}
int t,n;
ll a[maxx];
void Init()
{
    a[3]=4;
    for(int i=4; i<=2e6; i++)
    {
        if(i%3==0)
            a[i]=(a[i-1]+2*a[i-2]+4)%mod;
        else
            a[i]=(a[i-1]+2*a[i-2])%mod;
    }
}
int main()
{
    Init();
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n<3)
        {
            printf("0\n");
            continue;
        }
        else
        {
            printf("%lld\n",a[n]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout << #x << ": " << x << endl
#define debugs  cout<<"ssssss"<<endl
#define debugx  cout<<"xxxxxx"<<endl
#define __count(x) __builtin_popcount(x)
//返回二进制下有多少个1  int范围 后加l是 unsigned long 加ll是 unsigned long long
#define __ctz(x) __builtin_ctz(x)           //返回二进制下末尾有几个零
#define __ffs(x) __builtin_ffs(x)           //返回二进制下最后一个1的位置，从1开始
#define __max_elenment *max_element		   //返回一个数组的最大值,参数是数组的起始位置和结束位置
#define __min_elenment *min_element

using namespace std;
typedef long long ll;
const double pi=acos(-1);
const int maxx=2e6+10;
const int mod=1e9+7;
template<typename T>
inline T read()
{
    T s=0,f=1;
    char ch = getchar();
    while(!isdigit(ch))
    {
        if(ch == '-')
            f=-1;
        ch = getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+ch-48;
        ch = getchar();
    }
    return s*f;
}
#define gi() read<int>()
#define gl() read<ll>()
template<typename T>
inline void print(T x)
{
    if(x<0)
        putchar('-'), x=-x;
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}
int t,n;
ll a[maxx];

int main()
{

    t=gi();
    while(t--)
    {
        n=gi();
        if(n<3)
        {
            printf("0\n");
            continue;
        }
        else{
            a[3]=4;
            for(int i=4;i<=n;i++)
            {
                if(i%3==0)
                    a[i]=(a[i-1]+2*a[i-2]+4)%mod;
                else
                    a[i]=(a[i-1]+2*a[i-2])%mod;
            }
            printf("%lld\n",a[n]);
        }
   }
   return 0;
}


#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout << #x << ": " << x << endl
#define debugs  cout<<"ssssss"<<endl
#define debugx  cout<<"xxxxxx"<<endl
#define __count(x) __builtin_popcount(x)
//返回二进制下有多少个1  int范围 后加l是 unsigned long 加ll是 unsigned long long
#define __ctz(x) __builtin_ctz(x)           //返回二进制下末尾有几个零
#define __ffs(x) __builtin_ffs(x)           //返回二进制下最后一个1的位置，从1开始
#define __max_elenment *max_element		   //返回一个数组的最大值,参数是数组的起始位置和结束位置
#define __min_elenment *min_element

using namespace std;
typedef long long ll;
const double pi=acos(-1);
const int maxx=2e6+10;
const int mod=1e9+7;
template<typename T>
inline T read()
{
    T s=0,f=1;
    char ch = getchar();
    while(!isdigit(ch))
    {
        if(ch == '-')
            f=-1;
        ch = getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+ch-48;
        ch = getchar();
    }
    return s*f;
}
#define gi() read<int>()
#define gl() read<ll>()
template<typename T>
inline void print(T x)
{
    if(x<0)
        putchar('-'), x=-x;
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}
int t,n;
ll a[maxx];

int main()
{
  fio;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n<3)
        {
            cout<<0<<endl;
            continue;
        }
        else{
            a[3]=4;
            for(int i=4;i<=n;i++)
            {
                if(i%3==0)
                    a[i]=(a[i-1]+2*a[i-2]+4)%mod;
                else
                    a[i]=(a[i-1]+2*a[i-2])%mod;
            }
            cout<<a[n]<<endl;
        }
   }
   return 0;
}


#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout << #x << ": " << x << endl
#define debugs  cout<<"ssssss"<<endl
#define debugx  cout<<"xxxxxx"<<endl
#define __count(x) __builtin_popcount(x)
//返回二进制下有多少个1  int范围 后加l是 unsigned long 加ll是 unsigned long long
#define __ctz(x) __builtin_ctz(x)           //返回二进制下末尾有几个零
#define __ffs(x) __builtin_ffs(x)           //返回二进制下最后一个1的位置，从1开始
#define __max_elenment *max_element		   //返回一个数组的最大值,参数是数组的起始位置和结束位置
#define __min_elenment *min_element

using namespace std;
typedef long long ll;
const double pi=acos(-1);
const int maxx=2e6+10;
const int mod=1e9+7;
template<typename T>
inline T read()
{
    T s=0,f=1;
    char ch = getchar();
    while(!isdigit(ch))
    {
        if(ch == '-')
            f=-1;
        ch = getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+ch-48;
        ch = getchar();
    }
    return s*f;
}
#define gi() read<int>()
#define gl() read<ll>()
template<typename T>
inline void print(T x)
{
    if(x<0)
        putchar('-'), x=-x;
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}
int t,n;
ll a[maxx];
void Init()
{
    a[3]=4;
    for(int i=4; i<=n; i++)
    {
        if(i%3==0)
            a[i]=(a[i-1]+2*a[i-2]+4)%mod;
        else
            a[i]=(a[i-1]+2*a[i-2])%mod;
    }
}
int main()
{
    Init();
    t=gi();
    while(t--)
    {
        n=gi();
        if(n<3)
        {
            printf("0\n");
            continue;
        }
        else
        {
            printf("%lld\n",a[n]);
        }
    }
    return 0;
}


//Chaos///

#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#if DEBUG && !ONLINE_JUDGE

    #define debug(args...)     (Debugger()) , args
    //istringstream ss1(tmp11);
    class Debugger
    {
        public:
        Debugger(const std::string& _separator = ", ") :
        first(true), separator(_separator){}

        template<typename ObjectType>
        Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

    template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first)
                os << ", ";
            os << v[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
        {
            if(!first)
                os << ", ";
            os << *ii;
            first = false;
        }
        return os << "]";
    }

    template<typename T1, typename T2>
    inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
        {
            if(!first)
                os << ", ";
            os << *ii ;
            first = false;
        }
        return os << "]";
    }
#else
    #define debug(args...)
#endif
#define mod 1000000007
#define ok order_of_key
#define fo find_by_order
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repp(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define repl(i,a,b) for(ll i=(a);i<(b);i++)
#define newl cout<<'\n'
#define inf 1000000000
#define repaa(i,a) for(auto i=a.begin();i!=a.end();++i)
#define pb push_back
#define test cout<<"test"<<endl
#define start int tt;cin>>tt;while(tt--)
#define tc int tt;tt=read();while(tt--)
#define nl "\n"
#define startk int tt;cin>>tt;for(int kk=1;kk<=tt;kk++)
#define mem(v,i) memset(v,i,sizeof(v))//Use mem(v,60) to initialize with 10^9
#define all(x) x.begin(), x.end()
#define inf1 1e18
#define repa(i,a) for (auto i : a)
#define X first
#define Y second
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define dec(v) sort(v.begin(),v.end(),greater<int>());
#define in(a,n) repp(jjj,n)cin>>a[jjj];
#define re(a,n) repp(jjj,n)a[jjj]=read();
#define retree(a,m) repp(i,m){int tmp1=read()-1,tmp2=read()-1;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define intree(a,m) repp(i,m){int tmp1,tmp2;cin>>tmp1>>tmp2;tmp1--,tmp2--;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define ins insert
#define er erase
#define sz(a) (int)(a.size())
#define big cpp_int
#define ll128 int128_t //Write (ll128) when using this type.
#define print(x,n,k) repp(i,n){repp(j,k)cout<<x[i][j]<<"  ";newl;}
#define mt make_tuple
#define eb emplace_back
#define p_q priority_queue
#define time cerr << 1.0 * clock()
#define bp(i) __builtin_popcountll(i)
#define precision(x) cout << fixed << setprecision(x);
typedef long double ld;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pair<int,int>> vip;
typedef vector<pair<int,ll>> vil; // use for Dijkstra wih long weights
typedef vector<pair<ll,ll>> vll;
typedef pair<int, int> ip;
typedef pair<int, ll> il;
typedef pair<ll, ll> pll;
typedef tuple<int,int,int> state;
typedef tuple<ll,int,int> statel;
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
#endif
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
template<typename T>
T Min(T v) {
  return v;
}
template<typename T, typename... Args>
T Min(T first, Args... args) {
  return min(first , Min(args...));
}
template<typename T>
T Max(T v) {
  return v;
}
template<typename T, typename... Args>
T Max(T first, Args... args) {
  return max(first , Max(args...));
}
template<typename T>
T mult(T v) {
  return v;
}
template<typename T, typename... Args>
T mult(T first, Args... args) {
  return mult((first * mult(args...))%mod);
}
template<typename T>
T addr(T v) {
  return v;
}
template<typename T, typename... Args>
T addr(T first, Args... args) {
  return addr((first + addr(args...))%mod);
}
template<class T> inline bool remax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<class T> inline bool remin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class A, class B>
void add(A &a, B b)//adds in a. Does not return anything.
{
    a += b;
    if (a < 0LL) a += mod;
    if (a >= mod) a -= mod;
}
template<class A, class B>
void mul(A &a, B b)//adds in a. Does not return anything.
{
    a=(a*b)%mod;
}
inline int to_i(char c)
{
    return c - 'a';
}
/*
int n;
const int NNNN=1000*1000+5;
ll BITTree1[NNNN],BITTree2[NNNN];
ll getSum(ll BITree[],int index){
    ll sum = 0;
    index++;
    while (index>0){
        sum += BITree[index];
        index -= index & (-index);
    }
    return sum;
}
void updateBIT(ll BITree[],int index,ll val){
    index++;
    while (index <= n){
        BITree[index] += val;
        index += index & (-index);
    }
}
int sum(int x){
    return getSum(BITTree1,x)*x-getSum(BITTree2,x);
}
void updateRange(int l,int r,int val){
    updateBIT(BITTree1,l,val);
    updateBIT(BITTree1,r+1,-val);
    updateBIT(BITTree2,l,val*(l-1));
    updateBIT(BITTree2,r+1,-val*r);
}
ll rangeSum(int l, int r){
    return sum(r)-sum(l-1);
}
*/
/*
const int NN=2*1000*100+4;
int dsu[NN],sub[NN];
void pre(){
repp(i,NN)dsu[i]=i,sub[i]=1;
}
int root(int a){
    while(dsu[a]!=a){
        dsu[a]=dsu[dsu[a]];
        a=dsu[a];
    }
    return a;
}
void uni(int a,int b){
    int _a=root(a);
    int _b=root(b);
    if(_a==_b)return ;
    if(sub[_a]>sub[_b]){
        dsu[_b]=dsu[_a];
        sub[_a]+=sub[_b];
    }
    else {
        dsu[_a]=dsu[_b];
        sub[_b]+=sub[_a];
    }
}
*/
/*
const int LOGN=19,NNN=1000*1000+5;
int DP[LOGN][NN],level[NNN];
void dfs0(int u)
{
	for(auto it=a[u].begin();it!=a[u].end();it++)
		if(*it!=DP[0][u])
		{
			DP[0][*it]=u;
			level[*it]=level[u]+1;
			dfs0(*it);
		}
}
void preprocess()
{
	dfs0(0);
	for(int i=1;i<LOGN;i++)
		for(int j=0;j<n;j++)
			DP[i][j] = DP[i-1][DP[i-1][j]];
}
int lca(int a,int b)
{
	if(level[a]>level[b])swap(a,b);
	int d = level[b]-level[a];
	for(int i=0;i<LOGN;i++)
		if(d&(1<<i))
			b=DP[i][b];
	if(a==b)return a;
	for(int i=LOGN-1;i>=0;i--)
		if(DP[i][a]!=DP[i][b])
			a=DP[i][a],b=DP[i][b];
	return DP[0][a];
}
*/
/*
ll poww(ll a, ll b)
{
    ll val = 1;
    a %= mod;
    while (b > 0)
    {
        if (b % 2) val = mult(a, val);
        a = mult(a, a);
        b >>= 1;
    }
    return val % mod;
}
ll inv(ll a)
{
    return poww(a , mod - 2);
}
*/
/*
const int jj=2e5+5;
ll fac[jj];
void pre(){
    fac[0] = 1;
    for (int i=1 ; i<jj; i++)
    fac[i] = fac[i-1]*i%mod;
}
ll nc(int n,int r)
{
   if (r==0)
      return 1;
   return (fac[n]*inv(fac[r])%mod*inv(fac[n-r])%mod)%mod;
}
*/
/*
string to_str(ll a){
    string mystring;
    stringstream mystream;
    mystream << a;
    mystring = mystream.str();
    return mystring;
}
*/
/*
bool iscomp[100000];
vi primes;
void sieve(int n){
    for(int i=2;i<=n;++i){
        if(!iscomp[i]){
            primes.eb(i);
            for(int j=i*i;j<=n;j+=i)iscomp[j]=1;
        }
    }
}
*/
/*
vl prime(ll n){
    vl v;
    for(int i=2;i*i<=n;++i){
        if(n%i==0)v.eb(i);
        while(n%i==0)n/=i;
    }
    if(n!=1)v.eb(n);
    return v;
}
*/
/*
ll gcd1(ll a, ll b, ll &x, ll &y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd1(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) {
    g = gcd1(abs1(a), abs1(b), x0, y0);
    if (c % g!=0) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}
*/
/*
int cc(ll x){
    int ans=0;
    while(x){if(x&1LL)ans++;x/=2;}
    return ans;
}
*/
// Treap
// auto cmp = [](ip a, ip b){return a.X==b.X?a.Y>b.Y:a.X>b.X;};
 //   set<ip,decltype(cmp)> s(cmp);

//-----------------------------------------------------end--------------------------------------//

int main()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    tc{
        ll a=read(),b=read();
        ll diff = abs(a-b);
        a = max(a,b);
        b = a-diff;
        ll sum = 0;
        ll add = 1;
        while(sum < diff){sum+=add++;}
        if((sum - diff)%2==0)cout<<add-1;
        else cout<<add;
        newl;
    }
}


//Chaos///

#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#if DEBUG && !ONLINE_JUDGE

    #define debug(args...)     (Debugger()) , args
    //istringstream ss1(tmp11);
    class Debugger
    {
        public:
        Debugger(const std::string& _separator = ", ") :
        first(true), separator(_separator){}

        template<typename ObjectType>
        Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

    template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first)
                os << ", ";
            os << v[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
        {
            if(!first)
                os << ", ";
            os << *ii;
            first = false;
        }
        return os << "]";
    }

    template<typename T1, typename T2>
    inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
        {
            if(!first)
                os << ", ";
            os << *ii ;
            first = false;
        }
        return os << "]";
    }
#else
    #define debug(args...)
#endif
#define mod 1000000007
#define ok order_of_key
#define fo find_by_order
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repp(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define repl(i,a,b) for(ll i=(a);i<(b);i++)
#define newl cout<<'\n'
#define inf 1000000000
#define repaa(i,a) for(auto i=a.begin();i!=a.end();++i)
#define pb push_back
#define test cout<<"test"<<endl
#define start int tt;cin>>tt;while(tt--)
#define tc int tt;tt=read();while(tt--)
#define nl "\n"
#define startk int tt;cin>>tt;for(int kk=1;kk<=tt;kk++)
#define mem(v,i) memset(v,i,sizeof(v))//Use mem(v,60) to initialize with 10^9
#define all(x) x.begin(), x.end()
#define inf1 1e18
#define repa(i,a) for (auto i : a)
#define X first
#define Y second
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define dec(v) sort(v.begin(),v.end(),greater<int>());
#define in(a,n) repp(jjj,n)cin>>a[jjj];
#define re(a,n) repp(jjj,n)a[jjj]=read();
#define retree(a,m) repp(i,m){int tmp1=read()-1,tmp2=read()-1;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define intree(a,m) repp(i,m){int tmp1,tmp2;cin>>tmp1>>tmp2;tmp1--,tmp2--;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define ins insert
#define er erase
#define sz(a) (int)(a.size())
#define big cpp_int
#define ll128 int128_t //Write (ll128) when using this type.
#define print(x,n,k) repp(i,n){repp(j,k)cout<<x[i][j]<<"  ";newl;}
#define mt make_tuple
#define eb emplace_back
#define p_q priority_queue
#define time cerr << 1.0 * clock()
#define bp(i) __builtin_popcountll(i)
#define precision(x) cout << fixed << setprecision(x);
typedef long double ld;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pair<int,int>> vip;
typedef vector<pair<int,ll>> vil; // use for Dijkstra wih long weights
typedef vector<pair<ll,ll>> vll;
typedef pair<int, int> ip;
typedef pair<int, ll> il;
typedef pair<ll, ll> pll;
typedef tuple<int,int,int> state;
typedef tuple<ll,int,int> statel;
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
#endif
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
template<typename T>
T Min(T v) {
  return v;
}
template<typename T, typename... Args>
T Min(T first, Args... args) {
  return min(first , Min(args...));
}
template<typename T>
T Max(T v) {
  return v;
}
template<typename T, typename... Args>
T Max(T first, Args... args) {
  return max(first , Max(args...));
}
template<typename T>
T mult(T v) {
  return v;
}
template<typename T, typename... Args>
T mult(T first, Args... args) {
  return mult((first * mult(args...))%mod);
}
template<typename T>
T addr(T v) {
  return v;
}
template<typename T, typename... Args>
T addr(T first, Args... args) {
  return addr((first + addr(args...))%mod);
}
template<class T> inline bool remax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<class T> inline bool remin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class A, class B>
void add(A &a, B b)//adds in a. Does not return anything.
{
    a += b;
    if (a < 0LL) a += mod;
    if (a >= mod) a -= mod;
}
template<class A, class B>
void mul(A &a, B b)//adds in a. Does not return anything.
{
    a=(a*b)%mod;
}
inline int to_i(char c)
{
    return c - 'a';
}
/*
int n;
const int NNNN=1000*1000+5;
ll BITTree1[NNNN],BITTree2[NNNN];
ll getSum(ll BITree[],int index){
    ll sum = 0;
    index++;
    while (index>0){
        sum += BITree[index];
        index -= index & (-index);
    }
    return sum;
}
void updateBIT(ll BITree[],int index,ll val){
    index++;
    while (index <= n){
        BITree[index] += val;
        index += index & (-index);
    }
}
int sum(int x){
    return getSum(BITTree1,x)*x-getSum(BITTree2,x);
}
void updateRange(int l,int r,int val){
    updateBIT(BITTree1,l,val);
    updateBIT(BITTree1,r+1,-val);
    updateBIT(BITTree2,l,val*(l-1));
    updateBIT(BITTree2,r+1,-val*r);
}
ll rangeSum(int l, int r){
    return sum(r)-sum(l-1);
}
*/
/*
const int NN=2*1000*100+4;
int dsu[NN],sub[NN];
void pre(){
repp(i,NN)dsu[i]=i,sub[i]=1;
}
int root(int a){
    while(dsu[a]!=a){
        dsu[a]=dsu[dsu[a]];
        a=dsu[a];
    }
    return a;
}
void uni(int a,int b){
    int _a=root(a);
    int _b=root(b);
    if(_a==_b)return ;
    if(sub[_a]>sub[_b]){
        dsu[_b]=dsu[_a];
        sub[_a]+=sub[_b];
    }
    else {
        dsu[_a]=dsu[_b];
        sub[_b]+=sub[_a];
    }
}
*/
/*
const int LOGN=19,NNN=1000*1000+5;
int DP[LOGN][NN],level[NNN];
void dfs0(int u)
{
	for(auto it=a[u].begin();it!=a[u].end();it++)
		if(*it!=DP[0][u])
		{
			DP[0][*it]=u;
			level[*it]=level[u]+1;
			dfs0(*it);
		}
}
void preprocess()
{
	dfs0(0);
	for(int i=1;i<LOGN;i++)
		for(int j=0;j<n;j++)
			DP[i][j] = DP[i-1][DP[i-1][j]];
}
int lca(int a,int b)
{
	if(level[a]>level[b])swap(a,b);
	int d = level[b]-level[a];
	for(int i=0;i<LOGN;i++)
		if(d&(1<<i))
			b=DP[i][b];
	if(a==b)return a;
	for(int i=LOGN-1;i>=0;i--)
		if(DP[i][a]!=DP[i][b])
			a=DP[i][a],b=DP[i][b];
	return DP[0][a];
}
*/
/*
ll poww(ll a, ll b)
{
    ll val = 1;
    a %= mod;
    while (b > 0)
    {
        if (b % 2) val = mult(a, val);
        a = mult(a, a);
        b >>= 1;
    }
    return val % mod;
}
ll inv(ll a)
{
    return poww(a , mod - 2);
}
*/
/*
const int jj=2e5+5;
ll fac[jj];
void pre(){
    fac[0] = 1;
    for (int i=1 ; i<jj; i++)
    fac[i] = fac[i-1]*i%mod;
}
ll nc(int n,int r)
{
   if (r==0)
      return 1;
   return (fac[n]*inv(fac[r])%mod*inv(fac[n-r])%mod)%mod;
}
*/
/*
string to_str(ll a){
    string mystring;
    stringstream mystream;
    mystream << a;
    mystring = mystream.str();
    return mystring;
}
*/
/*
bool iscomp[100000];
vi primes;
void sieve(int n){
    for(int i=2;i<=n;++i){
        if(!iscomp[i]){
            primes.eb(i);
            for(int j=i*i;j<=n;j+=i)iscomp[j]=1;
        }
    }
}
*/
/*
vl prime(ll n){
    vl v;
    for(int i=2;i*i<=n;++i){
        if(n%i==0)v.eb(i);
        while(n%i==0)n/=i;
    }
    if(n!=1)v.eb(n);
    return v;
}
*/
/*
ll gcd1(ll a, ll b, ll &x, ll &y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd1(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) {
    g = gcd1(abs1(a), abs1(b), x0, y0);
    if (c % g!=0) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}
*/
/*
int cc(ll x){
    int ans=0;
    while(x){if(x&1LL)ans++;x/=2;}
    return ans;
}
*/
// Treap
// auto cmp = [](ip a, ip b){return a.X==b.X?a.Y>b.Y:a.X>b.X;};
 //   set<ip,decltype(cmp)> s(cmp);

//-----------------------------------------------------end--------------------------------------//

int main()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    tc{
        ll a=read(),b=read();
        ll diff = abs(a-b);
        a = max(a,b);
        b = a-diff;
        ll sum = 0;
        ll add = 1;
        while(sum < diff){sum+=add++;}
        while((sum - diff)%2!=0)sum+=add++;
        cout<<add - 1;
        newl;
    }
}