#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int T, g[3], tp, h;
long long n, f[3], c[4][4];
int main() {
  for (int i = 0; i < 4; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  for (scanf("%d", &T); T--;) {
    scanf("%lld", &n);
    f[0] = 1, f[1] = f[2] = 0;
    for (int i = 0; 1ll << i <= n; i++) {
      for (int j = 0; j < 3; j++) g[j] = (f[j] %= M), f[j] = 0;
      for (int j = 0; j < 3; j++) {
        tp = min(i + 1, 3), h = g[j];
        for (int k = (j + 1 & 1) == (n >> i & 1); k <= tp; k += 2)
          f[j + k >> 1] += c[tp][k] * g[j];
      }
    }
    printf("%d\n", f[0] % M);
  }
}
