#include <bits/stdc++.h>
using namespace std;
int j;
long long t, n, x, l = 1;
vector<long long> v;
int func(int x) {
  l++;
  j += (x % 4) + 2;
  if (j > 4) return (j % 4 == 0 ? 4 : j % 4);
  return j;
}
int main() {
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    j = 1;
    x = 0;
    l = 1;
    if (n == 1) {
      v.push_back(3);
      continue;
    } else
      while (j != 1 || (j == 1 && x == 0)) x += n - 1, j = func(n - 1);
    v.push_back(x + l);
  }
  for (int i = 0; i < t; i++) cout << v[i] << endl;
  getchar();
  getchar();
  return 0;
}
