#include <bits/stdc++.h>
using namespace std;
void read() {}
long long int a[32], b[32];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read();
  a[0] = 1;
  b[0] = 1;
  for (int i = 1; i < 32; i++) {
    a[i] = (1ll << i) + a[i - 1];
    b[i] = (1ll << i);
  }
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    long long int res = 1ll * n * (n + 1) / 2;
    for (int i = 31; i >= 0; i--)
      if (n >= b[i]) {
        res -= 2 * a[i];
        break;
      }
    cout << res << "\n";
  }
}
