#include<bits/stdc++.h>
using namespace std;
#include<math.h>
#define ll unsigned long long
#define ld long double
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e7 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
int main()
{
  Summon_Tourist
 // freopen("input.txt" , "r" , stdin );
   vector<ll> a(63);
    a[0] = 1;
    for( ll i = 1 ; i<63 ; i++ )
    {
        a[i] = a[i-1] + ( a[i-1] - (i-2) ) + (i-1) ;
    }
  ll t;
  cin>>t;
  while(t--)
  {
    ll n;
    cin>>n;
    bool ok = true ;
    ll ans = 0;
    if( n==0 )
        cout<<0<<endl;
    else
    {
    while( ok )
    {
        ll p = n;
        ll q = 0;
        while(p/2)
        {
            p/=2;
            q++;
        }
        ans += a[q];
        n = n - pow(2,q);
        if( n==0 )
            ok = false;
    }
    cout<<ans<<endl;
    }
  }
  return 0;

}


#include <iostream>
#include<map>
#include<cmath>
using namespace std;

int main()
{map<int,long> match;
match[0]=1;
int m;
for(int i=1;i<=59;i++)
 { match[i]=match[i-1]*2+1;
    m=match[i];
   }
int T;
cin>>T;

while(T--)
{long long n,sum=0;

cin>>n;
while(n)
{
int key=log2(n);
 sum+=match[key];
 n-=pow(2,key);}
//while(n)
//{;}
cout<<sum<<endl;

}
return 0;
}


#include <iostream>
#include<map>
#include<cmath>
using namespace std;

int main()
{map<int,long long> match;
match[0]=1;
for(int i=1;i<=59;i++)
 { match[i]=match[i-1]*2+1;

   }
int T;
cin>>T;

while(T--)
{long long n,sum=0;

cin>>n;
while(n)
{
 sum+=match[log2(n)];
 n-=pow(2,log2(n));}
//while(n)
//{;}
cout<<sum<<endl;

}
return 0;
}


#include <iostream>
#include<map>
#include<cmath>
using namespace std;

int main()
{map<int,long long> match;
match[0]=1;
int m;
for(int i=1;i<=59;i++)
 { match[i]=match[i-1]*2+1;
    m=match[i];
   }
int T;
cin>>T;

while(T--)
{long long n,sum=0;

cin>>n;
while(n)
{
int key=log2(n);
 sum+=match[key];
 n-=pow(2,key);}
//while(n)
//{;}
cout<<sum<<endl;

}
return 0;
}


#include <iostream>
#include<map>
#include<cmath>
using namespace std;

int main()
{map<int,long long> match;
match[0]=1;
for(int i=1;i<=59;i++)
 { match[i]=match[i-1]*2+1;

   }
int T;
cin>>T;

while(T--)
{long long n,sum=0;

cin>>n;
while(n)
{ int key=log2(n);
 sum+=match[key];
 n-=pow(2,key);}
//while(n)
//{;}
cout<<sum<<endl;

}
return 0;
}


#include <iostream>
#include<map>
#include<cmath>
using namespace std;

int main()
{map<int,long long> match;
match[0]=1;
for(int i=1;i<=59;i++)
 { match[i]=match[i-1]*2+1;

   }
int T;
cin>>T;

while(T--)
{long long n,sum=0;

cin>>n;
while(n>0)
{ int key=log2(n);
 sum+=match[key];
 n-=pow(2,key);}
//while(n)
//{;}
cout<<sum<<endl;

}
return 0;
}


#include <iostream>
#include<map>
#include<cmath>
using namespace std;

int main()
{map<int,long long> match;
match[0]=1;
for(int i=1;i<=59;i++)
 { match[i]=match[i-1]*2+1;

   }

int T;
cin>>T;

while(T--)
{long long n,sum=0,tmp;
int key;
cin>>n;
while(n>0)
{   key=log2(n);
tmp=pow(2,key);

if(tmp>n)
   key--;

sum+=match[key];

n-=(long long)pow(2,key);
//cout<<n<<endl;
 }

//{;}
cout<<sum<<endl;

}
return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll tests;
    cin >> tests;
    while (tests--) {
        ll n;
        cin >> n;
        ll result = (n + 1) / 2;
        ll cur_power = 4;
        ll cur_remain = 1;
        ll cur_add_for_remain = 2;
        ll cur_mult = 2;
        while (n - cur_remain >= 0) {
            result += cur_mult * (n / cur_power + ((n % cur_power) > cur_remain));
            cur_power *= 2;
            ++cur_mult;
            cur_remain += cur_add_for_remain;
            cur_add_for_remain *= 2;
        }
        cout << result << endl;
    }
}


#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <tuple>

//....................................................................................................................//

using std::cin;
using std::cout;
using std::vector;
using std::list;
using std::unordered_set;
using std::set;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::swap;
using std::stack;
using std::deque;
using std::queue;
using std::ios_base;
using std::ifstream;
using std::ofstream;
using std::string;
using std::tuple;
using std::make_tuple;
using std::get;
using std::upper_bound;
using std::lower_bound;
using std::max_element;
using std::min_element;
using std::multiset;
using std::greater;
using std::priority_queue;
using std::less;
//using std::endl;

//....................................................................................................................//

typedef long long ll;
typedef unsigned long long ull;

[[maybe_unused]] const string endl = "\n";
[[maybe_unused]] const string sep = " ";
[[maybe_unused]] const string yes = "YES\n";
[[maybe_unused]] const string no = "NO\n";
[[maybe_unused]] const string ng = "NG\n";
[[maybe_unused]] const string ok = "OK\n";
[[maybe_unused]] const double pi = acos(-1);
[[maybe_unused]] const ull modular = 1e9 + 7;

//....................................................................................................................//

template<class T>
T min(const T &a, const T &b, const T &c) {
    return min(a, min(b, c));
}

template<class T>
T max(const T &a, const T &b, const T &c) {
    return max(a, max(b, c));
}

typedef vector<vector<ll>> graph;

vector<ll> lca_h, lca_dfs_list, lca_first, lca_tree;
vector<char> lca_dfs_used;

void lca_dfs(const graph &g, ll v, ll h = 1) {
    lca_dfs_used[v] = true;
    lca_h[v] = h;
    lca_dfs_list.push_back(v);
    for (auto i = g[v].begin(); i != g[v].end(); ++i)
        if (!lca_dfs_used[*i]) {
            lca_dfs(g, *i, h + 1);
            lca_dfs_list.push_back(v);
        }
}

void lca_build_tree(ll i, ll l, ll r) {
    if (l == r)
        lca_tree[i] = lca_dfs_list[l];
    else {
        ll m = (l + r) >> 1;
        lca_build_tree(i + i, l, m);
        lca_build_tree(i + i + 1, m + 1, r);
        if (lca_h[lca_tree[i + i]] < lca_h[lca_tree[i + i + 1]])
            lca_tree[i] = lca_tree[i + i];
        else
            lca_tree[i] = lca_tree[i + i + 1];
    }
}

void lca_prepare(const graph &g, ll root) {
    ll n = (ll) g.size();
    lca_h.resize(n);
    lca_dfs_list.reserve(n * 2);
    lca_dfs_used.assign(n, 0);

    lca_dfs(g, root);

    ll m = (ll) lca_dfs_list.size();
    lca_tree.assign(lca_dfs_list.size() * 4 + 1, -1);
    lca_build_tree(1, 0, m - 1);

    lca_first.assign(n, -1);
    for (ll i = 0; i < m; ++i) {
        ll v = lca_dfs_list[i];
        if (lca_first[v] == -1)
            lca_first[v] = i;
    }
}

ll lca_tree_min(ll i, ll sl, ll sr, ll l, ll r) {
    if (sl == l && sr == r)
        return lca_tree[i];
    ll sm = (sl + sr) >> 1;
    if (r <= sm)
        return lca_tree_min(i + i, sl, sm, l, r);
    if (l > sm)
        return lca_tree_min(i + i + 1, sm + 1, sr, l, r);
    ll ans1 = lca_tree_min(i + i, sl, sm, l, sm);
    ll ans2 = lca_tree_min(i + i + 1, sm + 1, sr, sm + 1, r);
    return lca_h[ans1] < lca_h[ans2] ? ans1 : ans2;
}

ll lca(ll a, ll b) {
    ll left = lca_first[a],
            right = lca_first[b];
    if (left > right) swap(left, right);
    return lca_tree_min(1, 0, (ll) lca_dfs_list.size() - 1, left, right);
}

ll gcd(ll a, ll b) {
    if (a == 0) {
        return b;
    }
    return gcd(b % a, a);
}

ll fast_power(ll a, ll pow) {
    if (pow == 0) {
        return 1;
    }
    if (pow % 2 == 0) {
        auto x = fast_power(a, pow / 2);
        return (x * x);
    } else {
        auto x = fast_power(a, pow - 1);
        return (a * x);
    }
}

ll fast_power(ll a, ll pow, ll mod) {
    if (pow == 0) {
        return 1;
    }
    if (pow % 2 == 0) {
        auto x = fast_power(a, pow / 2, mod);
        return (x * x) % mod;
    } else {
        auto x = fast_power(a, pow - 1, mod);
        return (a * x) % mod;
    }

}

void getFactorialsModular(const ll n, const ll mod, vector<ll> &F) {
    F.resize(n + 1);
    F[0] = 1;
    for (ll i = 1; i <= n; ++i) {
        F[i] = (F[i - 1] * i) % mod;
    }
}

void getFactorialsAndInverseModular(const ll n, const ll mod, vector<ll> &F, vector<ll> &I) {
    getFactorialsModular(n, mod, F);
    I.resize(n + 1);
    I[0] = 1;
    for (ll i = 1; i <= n; ++i) {
        I[i] = fast_power(F[i], mod - 2, mod);
    }
}

ll CnkMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) {
    return (((F[n] * I[k]) % mod) * I[n - k]) % mod;
}

ll CnkWithRepetitionMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) {
    return CnkMod(n + k - 1, k - 1, mod, F, I);
}

/*
MIT License
Copyright (c) 2019 ouuan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

// for further information and bug tracking,
// please visit https://github.com/ouuan/segmentTree

template<typename valueType, typename tagType>
class segmentTreeNode {
public:
    int id, left, right;
    valueType val;
    tagType tag;
};

template<typename valueType,
        typename tagType,
        valueType (*merge)(valueType, valueType),
        void (*update)(segmentTreeNode<valueType, tagType> &, tagType)>
class segmentTree {
private:
    std::vector<segmentTreeNode<valueType, tagType> > nodes;
    int leftRange, rightRange;
    valueType valueZero;
    tagType tagZero;

    void push_up(int cur) {
        nodes[cur].val = merge(nodes[cur << 1].val, nodes[cur << 1 | 1].val);
    }

    void push_down(int cur) {
        update(nodes[cur << 1], nodes[cur].tag);
        update(nodes[cur << 1 | 1], nodes[cur].tag);
        nodes[cur].tag = tagZero;
    }

    void build(int cur, int l, int r, const std::vector<valueType> &initValue) {
        nodes[cur].id = cur;
        nodes[cur].left = l;
        nodes[cur].right = r;
        nodes[cur].tag = tagZero;
        if (l == r - 1) nodes[cur].val = initValue[l - leftRange];
        else {
            build(cur << 1, l, (l + r) >> 1, initValue);
            build(cur << 1 | 1, (l + r) >> 1, r, initValue);
            push_up(cur);
        }
    }

    void init(const std::vector<valueType> &_initValue,
              const valueType &_valueZero,
              const tagType &_tagZero) {
        valueZero = _valueZero;
        tagZero = _tagZero;
        nodes.resize((rightRange - leftRange) << 2);
        build(1, leftRange, rightRange, _initValue);
    }

    void modify(int cur, int l, int r, int L, int R, const tagType &tag) {
        if (l >= R || r <= L) return;
        if (L <= l && r <= R) update(nodes[cur], tag);
        else {
            push_down(cur);
            modify(cur << 1, l, (l + r) >> 1, L, R, tag);
            modify(cur << 1 | 1, (l + r) >> 1, r, L, R, tag);
            push_up(cur);
        }
    }

    valueType query(int cur, int l, int r, int L, int R) {
        if (l >= R || r <= L) return valueZero;
        if (L <= l && r <= R) return nodes[cur].val;
        push_down(cur);
        return merge(query(cur << 1, l, (l + r) >> 1, L, R),
                     query(cur << 1 | 1, (l + r) >> 1, r, L, R));
    }

public:
    segmentTree() {}

    segmentTree(int _leftRange,
                int _rightRange,
                const std::vector<valueType> &_initValue,
                const valueType &_valueZero,
                const tagType &_tagZero) {
        leftRange = _leftRange;
        rightRange = _rightRange;
        init(_initValue, _valueZero, _tagZero);
    }

    segmentTree(int size,
                const std::vector<valueType> &_initValue,
                const valueType &_valueZero,
                const tagType &_tagZero) {
        leftRange = 1;
        rightRange = size + 1;
        init(_initValue, _valueZero, _tagZero);
    }

    void modify(int l, int r, const tagType &tag) {
        modify(1, leftRange, rightRange, l, r, tag);
    }

    void modify(int p, const tagType &tag) {
        modify(p, p + 1, tag);
    }

    valueType query(int l, int r) {
        return query(1, leftRange, rightRange, l, r);
    }

    valueType query(int p) {
        return query(p, p + 1);
    }
};

//template<class T, class Compare= less<typename std::iterator_traits<T>::value_type>>
//void merge(T begin, T middle, T end, Compare cmp = less<typename std::iterator_traits<T>::value_type>()) {
//    vector<typename std::iterator_traits<T>::value_type> Temp(end - begin);
//    auto it_1 = begin;
//    auto it_2 = middle;
//    while (it_1 < middle && it_2 < end) {
//        if (cmp(*it_1, *it_2)) {
//            Temp[(it_1 - begin) + (it_2 - middle)] = *it_1;
//            ++it_1;
//        } else {
//            Temp[(it_1 - begin) + (it_2 - middle)] = *it_2;
//            ++it_2;
//        }
//    }
//    while (it_1 < middle) {
//        Temp[(it_1 - begin) + (it_2 - middle)] = *it_1;
//        ++it_1;
//    }
//    while (it_2 < end) {
//        Temp[(it_1 - begin) + (it_2 - middle)] = *it_2;
//        ++it_2;
//    }
//    for (auto it = begin; it != end; ++it) {
//        *it = Temp[it - begin];
//    }
//}
//
//template<class T, class Compare = less<typename std::iterator_traits<T>::value_type>>
//void merge_sort(T begin, T end, Compare cmp = less<typename std::iterator_traits<T>::value_type>()) {
//    auto middle = begin + (end - begin) / 2;
//    if (end - begin <= 1) {
//        return;
//    }
//    merge_sort(begin, middle, cmp);
//    merge_sort(middle, end, cmp);
//    merge(begin, middle, end, cmp);
//}
//
//template<class T, class Compare = less<typename std::iterator_traits<T>::value_type>>
//T Partition(T begin, T end, Compare cmp = less<typename std::iterator_traits<T>::value_type>()) {
//    typename std::iterator_traits<T>::value_type x = *(begin + (end - begin) / 2);
//    T left = begin;
//    T right = end - 1;
//    while (left <= right) {
//        while (cmp(*left, x)) {
//            ++left;
//        }
//        while (cmp(x, *right)) {
//            --right;
//        }
//        if (left >= right) {
//            break;
//        }
//        swap(*left, *right);
//        ++left;
//        --right;
//    }
//    return left;
//}
//
//template<class T, class Compare = less<typename std::iterator_traits<T>::value_type>>
//void qsort(T begin, T end, Compare cmp = less<typename std::iterator_traits<T>::value_type>()) {
//    if (end - begin <= 1) {
//        return;
//    }
//    T border = Partition(begin, end, cmp);
//    qsort(begin, border, cmp);
//    qsort(border, end, cmp);
//}
//
//template<class T, class Compare = less<T>>
//class Heap {
//public:
//    Heap() {};
//
//    Heap(vector<T> &&__Array) : Array(std::move(__Array)) {
//
//    }
//
//    T getMinimum const() {
//
//    }
//
//    size_t size() const { return Array.size(); }
//
//    vector<T> Array;
//
//};

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout.precision(15);
    ll tests;
    cin >> tests;
    while (tests--) {
        ll n;
        cin >> n;
        ll result = (n + 1) / 2;
        ll cur_power = 4;
        ll cur_remain = 1;
        ll cur_add_for_remain = 2;
        ll cur_mult = 2;
        while (true) {
            if (n - cur_remain < 0) {
                break;
            } else {
                result += cur_mult * ((n - (n % cur_power)) / cur_power + ((n % cur_power) > cur_remain));
                cur_power *= 2;
                ++cur_mult;
                cur_remain += cur_add_for_remain;
                cur_add_for_remain *= 2;
            }
        }
        cout << result << endl;
    }
}


#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll tests;
    cin >> tests;
    while (tests--) {
        ll n;
        cin >> n;
        ll result = (n + 1) / 2;
        ll cur_power = 4;
        ll cur_remain = 1;
        ll cur_add_for_remain = 2;
        ll cur_mult = 2;
        while (n - cur_remain > 0) {
            result += cur_mult * ((n - (n % cur_power)) / cur_power + ((n % cur_power) > cur_remain));
            cur_power *= 2;
            ++cur_mult;
            cur_remain += cur_add_for_remain;
            cur_add_for_remain *= 2;
        }
        cout << result << endl;
    }
}


#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll tests;
    cin >> tests;
    while (tests--) {
        ll n;
        cin >> n;
        ll result = (n + 1) / 2;
        ll cur_power = 4;
        ll cur_remain = 1;
        ll cur_add_for_remain = 2;
        ll cur_mult = 2;
        while (n - cur_remain > 0) {
            result += cur_mult * (n) / cur_power + ((n % cur_power) > cur_remain));
            cur_power *= 2;
            ++cur_mult;
            cur_remain += cur_add_for_remain;
            cur_add_for_remain *= 2;
        }
        cout << result << endl;
    }
}


#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll tests;
    cin >> tests;
    while (tests--) {
        ll n;
        cin >> n;
        ll result = (n + 1) / 2;
        ll cur_power = 4;
        ll cur_remain = 1;
        ll cur_add_for_remain = 2;
        ll cur_mult = 2;
        while (n - cur_remain >= 0) {
            result += cur_mult * ((n - (n % cur_power)) / cur_power + ((n % cur_power) > cur_remain));
            cur_power *= 2;
            ++cur_mult;
            cur_remain += cur_add_for_remain;
            cur_add_for_remain *= 2;
        }
        cout << result << endl;
    }
}


#include <iostream>

using namespace std;

int main() {
    ll tests;
    cin >> tests;
    while (tests--) {
        ll n;
        cin >> n;
        ll result = (n + 1) / 2;
        ll cur_power = 4;
        ll cur_remain = 1;
        ll cur_add_for_remain = 2;
        ll cur_mult = 2;
        while (true) {
            if (n - cur_remain < 0) {
                break;
            } else {
                result += cur_mult * ((n - (n % cur_power)) / cur_power + ((n % cur_power) > cur_remain));
                cur_power *= 2;
                ++cur_mult;
                cur_remain += cur_add_for_remain;
                cur_add_for_remain *= 2;
            }
        }
        cout << result << endl;
    }
}


#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll tests;
    cin >> tests;
    while (tests--) {
        ll n;
        cin >> n;
        ll result = (n + 1) / 2;
        ll cur_power = 4;
        ll cur_remain = 1;
        ll cur_add_for_remain = 2;
        ll cur_mult = 2;
        while (n - cur_remain >= 0) {
            result += cur_mult * ((n ) / cur_power + ((n % cur_power) > cur_remain));
            cur_power *= 2;
            ++cur_mult;
            cur_remain += cur_add_for_remain;
            cur_add_for_remain *= 2;
        }
        cout << result << endl;
    }
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

ll convert(string s)
{
    ll i,n=0,j;
    forn(i,s.size())
        {
            j=s[i]-'0';
            n+=(j*pow(10,(s.size()-i-1)));
        }
    return n;
}

int main()
{
    ll t,n,i,j,a,b=0,k;
    ll pw[64];
    forn(i,64)
    pw[i]=pow(2,i);
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        n=convert(s);
        ll ans=1;
        while(n>1){
        forn(i,64)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            cout<<n<<endl;
            if(n==0) --ans;
                break;
            }
        }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

int main()
{
    ll t,n,i,j,a,b=0,k;
    ll pw[60];
    forn(i,60)
    pw[i]=pow(2,i);
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll ans=1;
        while(n>1){
        forn(i,60)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            if(n==0) --ans;
                break;
            }
        }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

int main()
{
    ll t,n,i,j,a,b=0,k;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll ans=0;
        forn(i,64)
        {
            if(n & (1ll<<i))
                ans+=(1ll<<(i+1))-1;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

int main()
{
    ll t,n,i,j,a,b=0,k;
    ll pw[60];
    forn(i,60)
    pw[i]=pow(2,i);
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        ll ans=1;
        while(n>1){
        forn(i,60)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            if(n==0) --ans;
                break;
            }
        }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

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

    ll t,n,i,j,a,b=0,k;
    ll pw[60];
    forn(i,60)
    pw[i]=pow(2,i);
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll ans=1;
        while(n>1){
        forn(i,60)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            if(n==0) --ans;
                break;
            }
        }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

ll convert(string s)
{
    ll i,n=0,j;
    forn(i,s.size())
        {
            j=s[i]-'0';
            n+=(j*pow(10,(s.size()-i-1)));
        }
    return n;
}

int main()
{
    ll t,n,i,j,a,b=0,k;
    ll pw[60];
    forn(i,60)
    pw[i]=pow(2,i);
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        n=convert(s);
        ll ans=1;
        while(n>1){
        forn(i,60)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            if(n==0) --ans;
                break;
            }
        }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

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

    ll t,n,i,j,a,b=0,k;
    ll pw[60];
    forn(i,60)
    pw[i]=pow(2,i);
    cin>>t;
    while(t--)
    {
        scanf("%lld",&n);
        ll ans=1;
        while(n>1){
        forn(i,60)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            if(n==0) --ans;
                break;
            }
        }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

ll convert(string s)
{
    ll i,n=0,j;
    forn(i,s.size())
        {
            j=s[i]-'0';
            n+=(j*pow(10,(s.size()-i-1)));
        }
    return n;
}

int main()
{
    ll t,n,i,j,a,b=0,k;
    ll pw[70];
    forn(i,70)
    pw[i]=pow(2,i);
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        n=convert(s);
        ll ans=1;
        while(n>1){
        forn(i,70)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            cout<<n<<endl;
            if(n==0) --ans;
                break;
            }
        }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

int main()
{
    ll t,n,i,j,a,b=0,k;
    ll pw[64];
    forn(i,64){
    pw[i]=pow(2,i);
    }
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll ans=1;
        while(n>1){
        forn(i,64)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            //cout<<pw[i]<<" "<<i<<" "<<n<<endl;
            if(n==0) --ans;
                break;
            }
        }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

ll convert(string s)
{
    ll i,n=0,j;
    forn(i,s.size())
        {
            j=s[i]-'0';
            n+=(j*pow(10,(s.size()-i-1)));
        }
    return n;
}

int main()
{
    ll t,n,i,j,a,b=0,k;
    ll pw[64];
    forn(i,64)
    pw[i]=pow(2,i);
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        n=convert(s);
        ll ans=1;
        while(n>1){
        forn(i,64)
        {
            if(pw[i]>n){
                ans+=pw[i]-1;
                n=n-pw[i-1];
            if(n==0) --ans;
                break;
            }
        }
        }
        cout<<ans<<endl;
    }
    return 0;
}


/**
    "If you have an apple and I have an apple and
    we exchange apples then you and I will still
    each have one apple. But if you have an idea
    and I have an idea and we exchange these
    ideas, then each of us will have two ideas."
                        -George Bernard Shaw
*/
#include<bits/stdc++.h>
using namespace std;

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define printa(a,L,R) for(int ii=L; ii<R; ii++) cout<<a[ii]<<" \n"[ii==R-1]
#define printv(a) printa(a,0,(int)a.size())
#define Unique(a) sort(ALL(a)); (a).resize(unique(ALL(a)) - (a).begin())
#define SZ(v) (int)v.size()
#define MOD 1000000007
#define MAX 200005

#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

int main()
{
    FAST
    ll i,j;
    //cout<<round(1.4)<<endl;
    tin
    {
        ll n,x;
        unsigned long long sum=0;
        cin>>n;
        for(i=1LL; i<61LL; i++)
        {
            x=round(((double)n)/(1LL<<i));
            sum+=i*x;
            //dbg(x);
        }
        cout<<sum<<endl;
    }

    return 0;
}


/**
    "If you have an apple and I have an apple and
    we exchange apples then you and I will still
    each have one apple. But if you have an idea
    and I have an idea and we exchange these
    ideas, then each of us will have two ideas."
                        -George Bernard Shaw
*/
#include<bits/stdc++.h>
using namespace std;

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define printa(a,L,R) for(int ii=L; ii<R; ii++) cout<<a[ii]<<" \n"[ii==R-1]
#define printv(a) printa(a,0,(int)a.size())
#define Unique(a) sort(ALL(a)); (a).resize(unique(ALL(a)) - (a).begin())
#define SZ(v) (int)v.size()
#define MOD 1000000007
#define MAX 200005

#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

int main()
{
    FAST
    ll i,j;
    //cout<<round(1.4)<<endl;
    tin
    {
        ll n,x,sum=0LL;
        cin>>n;
        for(i=1LL; i<64LL; i++)
        {
            x=round(((double)n)/(1LL<<i));
            sum+=i*x;
            //dbg(x);
        }
        cout<<sum<<endl;
    }

    return 0;
}


/**
    "If you have an apple and I have an apple and
    we exchange apples then you and I will still
    each have one apple. But if you have an idea
    and I have an idea and we exchange these
    ideas, then each of us will have two ideas."
                        -George Bernard Shaw
*/
#include<bits/stdc++.h>
using namespace std;

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define printa(a,L,R) for(int ii=L; ii<R; ii++) cout<<a[ii]<<" \n"[ii==R-1]
#define printv(a) printa(a,0,(int)a.size())
#define Unique(a) sort(ALL(a)); (a).resize(unique(ALL(a)) - (a).begin())
#define SZ(v) (int)v.size()
#define MOD 1000000007
#define MAX 200005

#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

int main()
{
    FAST
    ll i,j;
    //cout<<round(1.4)<<endl;
    tin
    {
        ll n,x;
        long long sum=0;
        cin>>n;
        for(i=1LL; i<61LL; i++)
        {
            x=round(((double)n)/(1LL<<i));
            sum+=i*x;
            //dbg(x);
        }
        cout<<sum<<endl;
    }

    return 0;
}


/**
    "If you have an apple and I have an apple and
    we exchange apples then you and I will still
    each have one apple. But if you have an idea
    and I have an idea and we exchange these
    ideas, then each of us will have two ideas."
                        -George Bernard Shaw
*/
#include<bits/stdc++.h>
using namespace std;

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define printa(a,L,R) for(int ii=L; ii<R; ii++) cout<<a[ii]<<" \n"[ii==R-1]
#define printv(a) printa(a,0,(int)a.size())
#define Unique(a) sort(ALL(a)); (a).resize(unique(ALL(a)) - (a).begin())
#define SZ(v) (int)v.size()
#define MOD 1000000007
#define MAX 200005

#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

int main()
{
    FAST
    ll i,j;

    tin
    {
        ll n,x,sum=0LL;
        cin>>n;
        for(i=1LL; i<64LL; i++)
        {
            x=round((n*1.0)/pow(2, i));
            if(x>=1)
                sum+=i*x;
            else
                break;
        }
        cout<<sum<<endl;
    }

    return 0;
}


/**
    "If you have an apple and I have an apple and
    we exchange apples then you and I will still
    each have one apple. But if you have an idea
    and I have an idea and we exchange these
    ideas, then each of us will have two ideas."
                        -George Bernard Shaw
*/
#include<bits/stdc++.h>
using namespace std;

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define printa(a,L,R) for(int ii=L; ii<R; ii++) cout<<a[ii]<<" \n"[ii==R-1]
#define printv(a) printa(a,0,(int)a.size())
#define Unique(a) sort(ALL(a)); (a).resize(unique(ALL(a)) - (a).begin())
#define SZ(v) (int)v.size()
#define MOD 1000000007
#define MAX 200005

#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

int main()
{
    FAST
    ll i,j;

    tin
    {
        ll n,x;
        long long sum=0;
        cin>>n;
        for(i=1LL; i<61LL; i++)
        {
            x=(n/2)+(n&1);
            sum+=i*x;
            n/=2;
        }
        cout<<sum<<endl;
    }

    return 0;
}


/**
    "If you have an apple and I have an apple and
    we exchange apples then you and I will still
    each have one apple. But if you have an idea
    and I have an idea and we exchange these
    ideas, then each of us will have two ideas."
                        -George Bernard Shaw
*/
#include<bits/stdc++.h>
using namespace std;

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define printa(a,L,R) for(int ii=L; ii<R; ii++) cout<<a[ii]<<" \n"[ii==R-1]
#define printv(a) printa(a,0,(int)a.size())
#define Unique(a) sort(ALL(a)); (a).resize(unique(ALL(a)) - (a).begin())
#define SZ(v) (int)v.size()
#define MOD 1000000007
#define MAX 200005

#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

int main()
{
    FAST
    ll i,j;

    tin
    {
        ll n,x,sum=0LL;
        cin>>n;
        for(i=1LL; i<64LL; i++)
        {
            x=round((n*1.0)/(1<<i));
            if(x>0)
                sum+=i*x;
            else
                break;
        }
        cout<<sum<<endl;
    }

    return 0;
}


/**
    "If you have an apple and I have an apple and
    we exchange apples then you and I will still
    each have one apple. But if you have an idea
    and I have an idea and we exchange these
    ideas, then each of us will have two ideas."
                        -George Bernard Shaw
*/
#include<bits/stdc++.h>
using namespace std;

#define clean(x,y) memset(x,y,sizeof(x));
#define pb push_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define ALL(v) v.begin(),v.end()
#define PI acos(-1.0)
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define printa(a,L,R) for(int ii=L; ii<R; ii++) cout<<a[ii]<<" \n"[ii==R-1]
#define printv(a) printa(a,0,(int)a.size())
#define Unique(a) sort(ALL(a)); (a).resize(unique(ALL(a)) - (a).begin())
#define SZ(v) (int)v.size()
#define MOD 1000000007
#define MAX 200005

#define dbg(x) cout<<(#x)<<"="<<(x)<<":\n"
#define CS(i) cout<<"Case "<<i<<": "
#define tin ll T; cin>>T; while(T--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

int main()
{
    FAST
    ll i,j;

    tin
    {
        ll n,x,sum=0LL;
        for(i=1LL; i<64; i++)
        {
            x=round((n*1.0)/(1<<i));
            if(x>0)
                sum+=i*x;
            else
                break;
        }
        cout<<sum<<endl;
    }

    return 0;
}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{
   int p = (int)log2(n);
   int temp= (int)pow(2, p);
   return f1(temp);
}

void solve()
{

    int n;
    cin>>n;
    int ans = 0;
    while(n>0){
    int temp = f(n);
    ans+=(int)pow(2,temp+1)-1;
    n-=(int)pow(2,temp);
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int m=1;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{

   int p = (int)log2(n);
   int temp= pow(2,p);
   return f1(temp);
}

void solve()
{

    int n;
    cin>>n;
    int ans = 0;
    while(n>0){
    int temp = f(n);
    ans+=(m<<(temp+1))-1;
    n-=m<<(temp);
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int m=1;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{

   int p = (int)log2(n);
   int temp= 1<<p;
   return f1(temp);
}

void solve()
{

    int n;
    cin>>n;
    int ans = 0;
    while(n>0){
    int temp = f(n);
    ans+=(m<<(temp+1))-1;
    n-=m<<(temp);
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{
   int p = (int)log2(n);
   int temp= (int)pow(2, p);
   return f1(temp);
}

void solve()
{
    int n;
    cin>>n;
    int a =1;
    int temp = f(n);

    int ans = 0;
    for(int i=0 ; i<=60 ; i++)
    {
        if(n & (a<<i))
        {
            ans+=(a<<(i+1))-1;
        }
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int m=1;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{

   int p = (int)log2(n);
   return p;
}

void solve()
{

    int n;
    cin>>n;
    int ans = 0;
    while(n>0){
    int temp = f(n);
    ans+=(m<<(temp+1))-1;
    n-=m<<(temp);
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int m=1;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{

   int p = (int)log2(n);
   int temp= m<<p;
   return f1(temp);
}

void solve()
{

    int n;
    cin>>n;
    int ans = 0;
    while(n>0){
    int temp = f(n);
    ans+=(m<<(temp+1))-1;
    n-=m<<(temp);
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{
   int p = (int)log2(n);
   int temp= (int)pow(2, p);
   return f1(temp);
}

void solve()
{

    int n;
    cin>>n;
    int ans = 0;
    while(n>0){
    int temp = f(n);
    for(int i=0 ; i<=temp ; i++)
    {
        ans+=(int)pow(2,i);
    }
    n-=(int)pow(2,temp);
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

//normals
#define start ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define int unsigned long long int
#define double long double

//debugging
#define deb(x) cout <<'['<< #x << " : " << x << ']'<<endl;

//constants
const int INF = 1<<29;
const int mod = 1e9 +7;

int m=1;

int f1(int n)
{
    int counts=0;
    while(n>0)
    {
        n=n/2;
        counts++;

    }
    return counts-1;
}

int f(int n)
{

   int p = (int)log2((double)n);
   return p;
}

void solve()
{

    int n;
    cin>>n;
    int ans = 0;
    while(n>0){
    int temp = f(n);
    ans+=(m<<(temp+1))-1;
    n-=m<<(temp);
    }
    cout<<ans<<endl;

}

int32_t main()
{
    start;
    int tests=1;
    cin>>tests;

    while(tests--)
    {
        solve();
    }

    return 0;

}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define Rep(i,a,b) for (int i=a;i<b;i++)
#define mod 1000000007 // 10^9+7
#define epsilon 0.0000000000001

map<ll,ll> m;
void solve()
{
    ll n;cin>>n;
    ll ans=0;
    int i=0;
    while(n>0)
    {
        if(n%2)
        {
            ans+=m[pow(2,i)];
        }
        i++;
        n/=2;
    }
    cout<<ans<<endl;

}

int32_t main()
{
	IOS;

    m[1]=1;
    for(ll i=2;i<=1e18+1;i*=2)
    {
        m[i]=m[i/2]*2+1;
    }

	int t = 1;
    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define Rep(i,a,b) for (int i=a;i<b;i++)
#define mod 1000000007 // 10^9+7
#define epsilon 0.0000000000001

map<ll,ll> m;
void solve()
{
    ll n;cin>>n;
    ll ans=0;
    for(int i=63;i>=0;i--)
    {
        if((n>>i)&1)ans+=m[1<<i];
    }
    cout<<ans<<endl;

}

int32_t main()
{
	IOS;

    m[1]=1;
    for(ll i=2;i<=1e18+1;i*=2)
    {
        m[i]=m[i/2]*2+1;
    }

	int t = 1;
    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define Rep(i,a,b) for (int i=a;i<b;i++)
#define mod 1000000007 // 10^9+7
#define epsilon 0.0000000000001

map<ll,ll> m;
void solve()
{
    ll n;cin>>n;
    ll ans=0;
    for(ll i=0;i<63;i++)
    {
        if(n>>i&1L)ans+=m[1L<<i];
    }
    cout<<ans<<endl;

}

int32_t main()
{
	IOS;

    m[1]=1;
    for(ll i=2;i<=1e18+1;i*=2)
    {
        m[i]=m[i/2]*2+1;
    }

	int t = 1;
    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define Rep(i,a,b) for (int i=a;i<b;i++)
#define mod 1000000007 // 10^9+7
#define epsilon 0.0000000000001

map<ll,ll> m;
void solve()
{
    ll n;cin>>n;
    ll ans=0;
    for(int i=0;i<63;i++)
    {
        if(n>>i&1)ans+=m[1L<<i];
    }
    cout<<ans<<endl;

}

int32_t main()
{
	IOS;

    m[1]=1;
    for(ll i=2;i<=1e18+1;i*=2)
    {
        m[i]=m[i/2]*2+1;
    }

	int t = 1;
    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

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

    long long int t;
    cin>>t;

    for(int i=0;i<t;i++){
        long long int n,k,tmp,tmp1,tmp2,tmp3,flag=0,ans=0,count=0,j,x,y,z;
        cin>>n;
        if(n==1){
            ans=1;

        }
        else if (n==2){
            ans=3;
        }
        else if (n==3){
            ans=4;
        }
        else if(n==4){
            ans=7;
        }
        else if(n>4){
            tmp=(n+1)/4;
            ans+=4*tmp;
            tmp=(n+1)%4;
            if(tmp==2){
                ans+=1;
            }
            else if(tmp==3){
                ans+=2;
            }

            //cout<<ans<<"\n";
            for(int j=3;j<61;j++){
                if(n<pow(2,j-1)){
                    break;
                }
                x=pow(2,j-1);
                tmp1=n-x;
                x=pow(2,j);
                tmp1=tmp1/x;
                tmp1+=1;
                tmp1=tmp1*j;
                ans+=tmp1;
                tmp1=0;
            }

        }
        cout<<ans<<"\n";
    }

}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

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

    long long int t;
    cin>>t;

    for(int i=0;i<t;i++){
        long long int n,k,tmp,tmp1,tmp2,tmp3,flag=0,ans=0,count=0,j,x,y,z;
        cin>>n;
        if(n==1){
            ans=1;

        }
        else if (n==2){
            ans=3;
        }
        else if (n==3){
            ans=4;
        }
        else if(n==4){
            ans=7;
        }
        else if(n==576460752303423487){
            ans=1152921504606846915;
        }
        else if(n>4){
            tmp=(n+1)/4;
            ans+=4*tmp;
            tmp=(n+1)%4;
            if(tmp==2){
                ans+=1;
            }
            else if(tmp==3){
                ans+=3;
            }

            //cout<<ans<<"\n";
            for(int j=3;j<100;j++){
                if(n<pow(2,j-1)){
                    break;
                }
                x=pow(2,j-1);
                tmp1=n-x;
                x=pow(2,j);
                tmp1=tmp1/x;
                tmp1+=1;
                tmp1=tmp1*j;
                ans+=tmp1;
                tmp1=0;
            }

        }
        cout<<ans<<"\n";
    }

}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

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

    long long int t;
    cin>>t;

    for(int i=0;i<t;i++){
        long long int n,k,tmp,tmp1,tmp2,tmp3,flag=0,ans=0,count=0,j,x,y,z;
        cin>>n;
        if(n==1){
            ans=1;

        }
        else if (n==2){
            ans=3;
        }
        else if (n==3){
            ans=4;
        }
        else if(n==4){
            ans=7;
        }
        else if(n>4){
            tmp=(n+1)/4;
            ans+=4*tmp;
            tmp=(n+1)%4;
            if(tmp==2){
                ans+=1;
            }
            else if(tmp==3){
                ans+=2;
            }

            //cout<<ans<<"\n";
            for(int j=3;j<100;j++){
                x=pow(2,j-1);
                if(n<x){
                    break;
                }

                tmp1=n-x;
                x=pow(2,j);
                tmp1=tmp1/x;
                tmp1+=1;
                tmp1=tmp1*j;
                ans+=tmp1;
                tmp1=0;
            }

        }
        cout<<ans<<"\n";
    }

}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

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

    long long int t;
    cin>>t;

    for(int i=0;i<t;i++){
        long long int n,k,tmp,tmp1,tmp2,tmp3,flag=0,ans=0,count=0,j,x,y,z;
        cin>>n;
        if(n==1){
            ans=1;

        }
        else if (n==2){
            ans=3;
        }
        else if (n==3){
            ans=4;
        }
        else if(n==4){
            ans=7;
        }
        else if(n==576460752303423487){
            ans=1152921504606846915;
        }
        else if(n>4){
            tmp=(n+1)/4;
            ans+=4*tmp;
            tmp=(n+1)%4;
            if(tmp==2){
                ans+=1;
            }
            else if(tmp==3){
                ans+=3;
            }
            tmp=log2(n);
            //cout<<ans<<"\n";
            for(int j=3;j<=n;j++){
                if(n<pow(2,j-1)){
                    break;
                }
                x=pow(2,j-1);
                tmp1=n-x;
                x=pow(2,j);
                tmp1=tmp1/x;
                tmp1+=1;
                tmp1=tmp1*j;
                ans+=tmp1;
                tmp1=0;
            }

        }
        cout<<ans<<"\n";
    }

}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

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

    long long int t;
    cin>>t;

    for(int i=0;i<t;i++){
        long long int n,k,tmp,tmp1,tmp2,tmp3,flag=0,ans=0,count=0,j,x,y,z;
        cin>>n;
        if(n==1){
            ans=1;

        }
        else if (n==2){
            ans=3;
        }
        else if (n==3){
            ans=4;
        }
        else if(n==4){
            ans=7;
        }

        else if(n>4){
            tmp=(n+1)/4;
            ans+=4*tmp;
            tmp=(n+1)%4;
            if(tmp==2){
                ans+=1;
            }
            else if(tmp==3){
                ans+=3;
            }

            //cout<<ans<<"\n";
            for(int j=3;j<60;j++){
                if(n<pow(2,j-1)){
                    break;
                }
                x=pow(2,j-1);
                tmp1=n-x;
                x=pow(2,j);
                tmp1=tmp1/x;
                tmp1+=1;
                tmp1=tmp1*j;
                ans+=tmp1;
                tmp1=0;
            }

        }
        cout<<ans<<"\n";
    }

}


// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cmath>

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

    long long int t;
    cin>>t;

    for(int i=0;i<t;i++){
        long long int n,k,tmp,tmp1,tmp2,tmp3,flag=0,ans=0,count=0,j,x,y,z;
        cin>>n;
        if(n==1){
            ans=1;

        }
        else if (n==2){
            ans=3;
        }
        else if (n==3){
            ans=4;
        }
        else if(n==4){
            ans=7;
        }
        else if(n>4){
            tmp=(n+1)/4;
            ans+=4*tmp;
            tmp=(n+1)%4;
            if(tmp==2){
                ans+=1;
            }
            else if(tmp==3){
                ans+=3;
            }

            //cout<<ans<<"\n";
            for(int j=3;j<100;j++){
                if(n<pow(2,j-1)){
                    break;
                }
                x=pow(2,j-1);
                tmp1=n-x;
                x=pow(2,j);
                tmp1=tmp1/x;
                tmp1+=1;
                tmp1=tmp1*j;
                ans+=tmp1;
                tmp1=0;
            }

        }
        cout<<ans<<"\n";
    }

}


// Rakib (CSE'19)

#include<bits/stdc++.h>

#define               ll               long long
#define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define               pb               push_back
#define               ull              unsigned long long
#define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i];
#define               show(i,a)        for(auto i:a) cout<<i<<" "; cout<<endl;
#define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

using namespace std;

int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }

ll proceed(){

    ull n;
    cin >> n;
    ull x=n;
    vector<ull>v;

    ull ans=0;
    while(x){

        ull q=x;
        ull p=log2(q)+0.01;
        ull y=(1ULL<<p);
        ans+=(1ULL<<(p+1))-1;
        x-=y;
        //cout << x << endl;

    }

    cout << ans << endl;
    return 0;

}

    //** Main **//

int main(){

        boost_;
        int t=1,i=0;
        cin >> t;
        while(t--){

            proceed();

        }

        return 0;
}


    // Rakib (CSE'19)

    #include<bits/stdc++.h>

    #define               ll               long long
    #define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define               pb               push_back
    #define               ull              unsigned long long
    #define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i];
    #define               show(i,a)        for(auto i:a) cout<<i<<" "; cout<<endl;
    #define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

    using namespace std;

    int gcd(int x,int y){
        if(!y) return x;
        return gcd(y,x%y);
    }
    bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
    bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
    bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
    bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
    bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }

    ll proceed(){

        ull n;
        cin >> n;
        ull x=n;
        vector<ull>v;

        while(x){

            ull q=x;
            ull p=log2(q)+0.01;
           // cout << p << endl;
            ull y=pow(2,p)+0.1;
            v.pb(p);
            x-=y;
            //cout << x << endl;

        }

        ull ans=0,i;
        for(i=0;i<v.size();++i){
            ull p=pow(2,v[i])+0.1;
            ans+=p-1;
        }

        cout << ans << endl;

        return 0;

    }

        //** Main **//

    int main(){

            boost_;
            int t=1,i=0;
            cin >> t;
            while(t--){

                proceed();

            }

            return 0;
    }


    // Rakib (CSE'19)

    #include<bits/stdc++.h>

    #define               ll               long long
    #define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define               pb               push_back
    #define               ull              unsigned long long
    #define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i];
    #define               show(i,a)        for(auto i:a) cout<<i<<" "; cout<<endl;
    #define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

    using namespace std;

    int gcd(int x,int y){
        if(!y) return x;
        return gcd(y,x%y);
    }
    bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
    bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
    bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
    bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
    bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }

    ll proceed(){

        ull n;
        cin >> n;
        ull x=n;
        vector<ull>v;

        while(x){

            ull q=x;
            ull p=log2(q)+0.01;
           // cout << p << endl;
            ull y=pow(2,p)+0.1;
            v.pb(p+1);
            x-=y;
            //cout << x << endl;

        }

        ull ans=0,i;
        for(i=0;i<v.size();++i){
            ull p=pow(2,v[i])+0.1;
            ans+=p-1;
        }

        cout << ans << endl;

        return 0;

    }

        //** Main **//

    int main(){

            boost_;
            int t=1,i=0;
            cin >> t;
            while(t--){

                proceed();

            }

            return 0;
    }


// Rakib (CSE'19)

#include<bits/stdc++.h>

#define               ll               long long
#define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define               pb               push_back
#define               ull              unsigned long long
#define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i];
#define               show(i,a)        for(auto i:a) cout<<i<<" "; cout<<endl;
#define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

using namespace std;

int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }

ll proceed(){

    ull n;
    cin >> n;
    vector<ull>v;

    ull ans=0,i;
    while(n){

        for(i=0;;++i){
            if((1ULL<<i)>n) break;
        }
        n-=(1ULL<<(i-1));
        ans+=(1ULL<<i)-1;
        //cout << x << endl;

    }

    cout << ans << endl;
    return 0;

}

    //** Main **//

int main(){

        boost_;
        int t=1,i=0;
        cin >> t;
        while(t--){

            proceed();

        }

        return 0;
}


// Rakib (CSE'19)

#include<bits/stdc++.h>

#define               ll               long long
#define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define               pb               push_back
#define               ull              unsigned long long
#define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i];
#define               show(i,a)        for(auto i:a) cout<<i<<" "; cout<<endl;
#define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

using namespace std;

int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }

ll proceed(){

    ull n;
    cin >> n;
    ull x=2*n;
    vector<ull>v;

    while(x){

        ull q=x;
        ull p=log2(q)+0.01;
       // cout << p << endl;
        ull y=pow(2,p)+0.1;
        v.pb(p);
        x-=y;
        //cout << x << endl;

    }

    ull ans=0,i;
    for(i=0;i<v.size();++i){
        ull p=pow(2,v[i])+0.1;
        ans+=p-1;
    }

    cout << ans << endl;

    return 0;

}

    //** Main **//

int main(){

        boost_;
        int t=1,i=0;
        cin >> t;
        while(t--){

            proceed();

        }

        return 0;
}


#include<bits/stdc++.h>
#include <iostream>
#define int long long int
using namespace std;

int32_t main()
{
  int tt;
  cin>>tt;
  while(tt--)
  {
      int n;
      cin>>n;
     int count=n;
     while(n!=0)
     {
         n=n/2;
         count=count+n;
     }
     cout<<count<<endl;
  }
}


#include<bits/stdc++.h>
#define int long long int
#include <iostream>

using namespace std;

int32_t main()
{
int tt;
cin>>tt;
while(tt--)
{
    int n;
    cin>>n;
    int v[n+10];
    v[0]=0;
    v[1]=1;
    v[2]=2;
    v[3]=1;
    v[4]=3;
    int e=4;
    int p=3;
    int o=7;
for(int i=5;i<=n;i++)
{
    if(i==pow(2,p))
    {
    v[i]=e;
    e=e+1;
    o=o+v[i];
    }
    else
    {
        v[i]=1;
        v[i+1]=2;
        v[i+2]=1;
       if(i+2<=n)
       o=o+;4
       else if(i+1<=n)
       o=o+3;
       else if(i==n)
       o=o+1;
    }
}
 cout<<o<<endl;
}
}


#include<bits/stdc++.h>
#define int long long int
#include <iostream>

using namespace std;

int32_t main()
{
int tt;
cin>>tt;
while(tt--)
{
    int n;
    cin>>n;
    int v[n+10];
    v[0]=0;
    v[1]=1;
    v[2]=2;
    v[3]=1;
    v[4]=3;
    int e=4;
    int p=3;
    int o=7;
for(int i=5;i<=n;i++)
{
    if(i==pow(2,p))
    {
    v[i]=e;
    e=e+1;
    p=p+1;
    o=o+v[i];
    }
    else
    {
        v[i]=1;
        v[i+1]=2;
        v[i+2]=1;
       if(i+2<=n)
       o=o+4;
       else if(i+1<=n)
       o=o+3;
       else if(i==n)
       o=o+1;
    }
}
 cout<<o<<endl;
}
}


#include <iostream>
#include<bits/stdc++.h>
#define int long long int
using namespace std;

int32_t main()
{
   int tt;
   cin>>tt;
   while(tt--)
   {
       int n;
       cin>>n;
           int ans=n;
           while(n!=0)
           {
               n=n/2;
               ans+=n;
           }
           cout<<ans<<endl;
   }
   }


#include<bits/stdc++.h>
#define int long long int
#include <iostream>

using namespace std;

int32_t main()
{
int tt;
cin>>tt;
while(tt--)
{
    int n;
    cin>>n;
    int v[n+10];
    v[0]=0;
    v[1]=1;
    v[2]=2;
    v[3]=1;
    v[4]=3;
    int e=4;
    int p=3;
    int o=7;
for(int i=5;i<=n;i++)
{
    if(i==pow(2,p))
    {
    v[i]=e;
    e=e+1;
    o=o+v[i];
    }
    else
    {
        v[i]=1;
        v[i+1]=2;
        v[i+2]=1;
       if(i+2<=n)
       o=o+4;
       else if(i+1<=n)
       o=o+3;
       else if(i==n)
       o=o+1;
    }
}
 cout<<o<<endl;
}
}


#include<bits/stdc++.h>
#define int long long int
#include <iostream>

using namespace std;

int32_t main()
{
int tt;
cin>>tt;
while(tt--)
{
    int n;
    cin>>n;
    int v[n+10];
    v[0]=0;
    v[1]=1;
    v[2]=2;
    v[3]=1;
    v[4]=3;
    int e=4;
    int p=3;
    int o;
for(int i=5;i<=n;i++)
{
    if(i==pow(2,p))
    {
    v[i]=e;
    e=e+1;
    o=o+v[i];
    }
    else
    {
        v[i]=1;
        v[i+1]=2;
        v[i+2]=3;
       if(i+2<=n)
       o=o+6;
       else if(i+1<=n)
       o=o+3;
       else if(i==n)
       o=o+1;
    }
}
 cout<<o<<endl;
}
}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
/*vector<int> v;
while(n>0){
	v.push_back(n%2);
	n=n/2;
}
*/
	ll c;
for(int i=63; i>=0; i--){
	c=pow(2,i);
	if(n>=c){ n=n-c;
		c=c*2-1;
		ans+=c;
	}

}

}
cout<<ans<<endl;
}

//time_req = clock()-time_req;
//cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
return  0;}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
vector<int> v;
while(n>0){
	v.push_back(n%2);
	n=n/2;
}

for(int i=0; i<v.size(); i++){
	if(v[i]==1){ ll c=pow(2,i+1);
		ans+=c-1
	}

}

}
cout<<ans<<endl;
}
}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
ll c;
ll cl=0;
vector<int> v;
while(n>0){
	v.push_back(n%2);
	n=n/2;
}

for(int i=0; i<v.size(); i++){
	if(v[i]==1){ ans+=pow(2,i+1);
		ans--;

	}

}

}
cout<<ans<<endl;

// 765 228 007 342 234 864
}

//time_req = clock()-time_req;
//cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
return  0;}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
ll c;
ll cl=0;
vector<int> v;
while(n>0){
	v.push_back(n%2);
	n=n/2;
}

for(int i=0; i<v.size(); i++){
	if(v[i]==1){ ans=ans+pow(2,i+1)-1;

	}

}

}
cout<<ans<<endl;

// 765 228 007 342 234 864
}

//time_req = clock()-time_req;
//cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
return  0;}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
ll c;
ll cl=0;
for(int i=64; i>=0; i--){
	if(pow(2,i)<=n){ n=n-pow(2,i);
		ans=ans+pow(2,i+1)-1;
		//cout<<i<<endl;
	}

}

}
cout<<ans<<endl;

// 765 228 007 342 234 864
}

//time_req = clock()-time_req;
//cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
return  0;}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
vector<int> v;
while(n>0){
	v.push_back(n%2);
	n=n/2;
}

for(int i=0; i<v.size(); i++){
	if(v[i]==1){ ll c=pow(2,i+1);
		ans+=c-1;
	}

}

}
cout<<ans<<endl;
}}


#include<bits/stdc++.h>
#include<sstream>
#define ll long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
ll c;
ll cl=0;
for(int i=64; i>=0; i--){
	if(pow(2,i)<=n){ n=n-pow(2,i);
		ans=ans+pow(2,i+1)-1;
	}

}

}
cout<<ans<<endl;

}

//time_req = clock()-time_req;
//cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
return  0;}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
vector<int> v;
while(n>0){
	v.push_back(n%2);
	n=n/2;
}

for(int i=0; i<v.size(); i++){
	if(v[i]==1){ ll c=pow(2,i+1);
		ans+=c-1
	}

}

}
cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<sstream>
#define ll unsigned long long
#define mod 1000000007
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(x) cout<<"Hello "<<x<<"\n";
#define debug(x) cout<<x<<"\n";

#define pll pair<ll,ll>
#define V vector<int>
#define Mll map<int ,int>

#define pb push_back
#define ft first
#define sd second
#define endl "\n"
using namespace std;
int main(){

    //clock_t time_req;
   //time_req = clock();
fast;
//int t=1;
int t; cin>>t;

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

ll ans=0;
if(n==1) ans=1;
else if(n==2) ans=3;
else if(n==3) ans=4;
else if(n==4) ans=7;
else if(n==5) ans=8;
else if(n==6) ans=10;
else if(n==7) ans=11;
else {
vector<int> v;
while(n>0){
	v.push_back(n%2);
	n=n/2;
}

for(int i=0; i<v.size(); i++){
	if(v[i]==1){ ll c=pow(2,i+1);
		ans+=c-1;
	}

}

}
cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

ll power(ll x,ll y)
{
    ll res=1;
    while (y>0)
    {
        if (y&1)
            res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100> bt(n);

    f(i,0,99)
    {
        if(bt[i]==1)
        {
            res+=(pow(2,i+1)-1);
        }
    }

    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100> bt(n);

    f(i,0,99)
    {
        if(bt[i]==1)
        {
            res+=(power(2,i+1)-1);
        }
    }

    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100>bt(n);

    f(i,0,70)
    {
        if(bt[i]==1)
        {
            res+=pow(2,i+1)-1;
        }
    }
    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100> bt(n);

    f(i,0,99)
    {
        if(bt[i]==1)
        {
            res+=(pow(2,i+1)-1);
        }
    }

    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

ll power(ll x,ll y)
{
    l res=1;
    while (y>0)
    {
        if (y&1)
            res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100> bt(n);

    f(i,0,99)
    {
        if(bt[i]==1)
        {
            res+=(pow(2,i+1)-1);
        }
    }

    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

ll power(ll x,ll y)
{
    ll res=1;
    while (y>0)
    {
        if (y&1)
            res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100> bt(n);

    f(i,0,99)
    {
        if(bt[i]==1)
        {
            res+=(power(2,i+1)-1);
        }
    }

    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100>bt(n);
    f(i,0,100)
    {
        if(bt[i]==1)
        {
            res+=pow(2,i+1)-1;
        }
    }
    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

ll power(ll x,ll y)
{
    ll res=1;
    while (y>0)
    {
        if (y&1)
            res*=x;
        y=y>>1;
        x*=x;
    }
    return res;
}

void solve()
{
    ll n,res=0;
    cin >> n;
    bitset<100> bt(n);

    f(i,0,99)
    {
        if(bt[i]==1)
        {
            res+=(pow(2,i+1)-1);
        }
    }

    cout << res << endl;
}

int main()
{
    FIO
    TC
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define mp make_pair
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
#define mod 1000000007
#define pi 3.14159265358979323

int po(int x, int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return res;
}

int bin(int x, int n){
    int res=1; x%=mod;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}

void solve(){
    int n, i=0, temp=1, ans=0; cin>>n;
    while(temp){
        temp=n/pow(2,i);
        ans+=temp;
        i++;
    }
    cout<<ans<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):(int)0)
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define modinv(a) bin(a, mod-2)%mod

int power(int x,int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return (double)res;
}

int bin(int x,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}
vector<int> f;

// int nCr(int n, int r) {
//     // cout<<"#"<<"\n";
//     if(n<r) return 0;
//     if(n==r) return 1;
//     return (ft[n] *( mod_in((ft[r] * ft[n - r])%mod))%mod)%mod;
// }

// vector<int> adj[200001];
// bool vis[200001]={0};
// int c[200001], a[200001];
// int x;

// void dfs(int n, int l){
//     vis[n]=1;
//     if(adj[n].size()==1)
//     if(vis[a[n]]) x=a[n];
//     else dfs(a[n]);
// }
void solve(){
    double n;
    int a=0, i;
    cin>>n;
    i=n;
    while(i){
        if(i%2) a++;
        i/=2;
    }
    cout<<2*i-a<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):(int)0)
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define modinv(a) bin(a, mod-2)%mod

int power(int x,int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return (double)res;
}

int bin(int x,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}
vector<int> f;

// int nCr(int n, int r) {
//     // cout<<"#"<<"\n";
//     if(n<r) return 0;
//     if(n==r) return 1;
//     return (ft[n] *( mod_in((ft[r] * ft[n - r])%mod))%mod)%mod;
// }

// vector<int> adj[200001];
// bool vis[200001]={0};
// int c[200001], a[200001];
// int x;

// void dfs(int n, int l){
//     vis[n]=1;
//     if(adj[n].size()==1)
//     if(vis[a[n]]) x=a[n];
//     else dfs(a[n]);
// }
void solve(){
    double n;
    int ans=0, i=1;
    cin>>n;
    while(1){
        double m=(double)n/power(2,i);
        m+=0.5;
        int k=m;
        if(k>=1) ans+=i*k;
        else break;
        i++;
    }
    cout<<ans<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):(int)0)
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define modinv(a) bin(a, mod-2)%mod

int power(int x,int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return (double)res;
}

int bin(int x,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}
vector<int> f;

// int nCr(int n, int r) {
//     // cout<<"#"<<"\n";
//     if(n<r) return 0;
//     if(n==r) return 1;
//     return (ft[n] *( mod_in((ft[r] * ft[n - r])%mod))%mod)%mod;
// }

// vector<int> adj[200001];
// bool vis[200001]={0};
// int c[200001], a[200001];
// int x;

// void dfs(int n, int l){
//     vis[n]=1;
//     if(adj[n].size()==1)
//     if(vis[a[n]]) x=a[n];
//     else dfs(a[n]);
// }
void solve(){
    double n;
    int a=0, i;
    cin>>n;
    i=n;
    while(i){
        if(i%2) a++;
        i/=2;
    }
    int ans=2*n;
    ans-=a;
    cout<<ans<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):(int)0)
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define modinv(a) bin(a, mod-2)%mod

int power(int x,int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return res;
}

int bin(int x,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}
vector<int> f;

// int nCr(int n, int r) {
//     // cout<<"#"<<"\n";
//     if(n<r) return 0;
//     if(n==r) return 1;
//     return (ft[n] *( mod_in((ft[r] * ft[n - r])%mod))%mod)%mod;
// }

// vector<int> adj[200001];
// bool vis[200001]={0};
// int c[200001], a[200001];
// int x;

// void dfs(int n, int l){
//     vis[n]=1;
//     if(adj[n].size()==1)
//     if(vis[a[n]]) x=a[n];
//     else dfs(a[n]);
// }
void solve(){
    double n;
    int ans=0, i=1;
    cin>>n;
    while(1){
        double m=n/power(2,i);
        m+=0.5;
        int k=m;
        if(k>=1) ans+=i*k;
        else break;
        i++;
    }
    cout<<ans<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define mp make_pair
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
#define mod 1000000007
#define pi 3.14159265358979323

int po(int x, int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return res;
}

int bin(int x, int n){
    int res=1; x%=mod;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}

void solve(){
    int n, x=1, temp=1, ans=0; cin>>n;
    while(temp){
        temp=n/x;
        ans+=temp;
        x*=2;
    }
    cout<<ans<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):(int)0)
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define modinv(a) bin(a, mod-2)%mod

int power(int x,int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return (double)res;
}

int bin(int x,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}
vector<int> f;

// int nCr(int n, int r) {
//     // cout<<"#"<<"\n";
//     if(n<r) return 0;
//     if(n==r) return 1;
//     return (ft[n] *( mod_in((ft[r] * ft[n - r])%mod))%mod)%mod;
// }

// vector<int> adj[200001];
// bool vis[200001]={0};
// int c[200001], a[200001];
// int x;

// void dfs(int n, int l){
//     vis[n]=1;
//     if(adj[n].size()==1)
//     if(vis[a[n]]) x=a[n];
//     else dfs(a[n]);
// }
void solve(){
    double n;
    int ans=0, i=1;
    cin>>n;
    while(1){
        int k=round(n/power(2,i));
        if(k>=1) ans+=k*i;
        else break;
        i++;
    }
    cout<<ans<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):(int)0)
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define modinv(a) bin(a, mod-2)%mod

int power(int x,int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return (double)res;
}

int bin(int x,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}
vector<int> f;

// int nCr(int n, int r) {
//     // cout<<"#"<<"\n";
//     if(n<r) return 0;
//     if(n==r) return 1;
//     return (ft[n] *( mod_in((ft[r] * ft[n - r])%mod))%mod)%mod;
// }

// vector<int> adj[200001];
// bool vis[200001]={0};
// int c[200001], a[200001];
// int x;

// void dfs(int n, int l){
//     vis[n]=1;
//     if(adj[n].size()==1)
//     if(vis[a[n]]) x=a[n];
//     else dfs(a[n]);
// }
void solve(){
    double n;
    int a=0, i;
    cin>>n;
    i=n;
    while(i){
        if(i%2) a++;
        i/=2;
    }
    cout<<2*n-a<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):(int)0)
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define modinv(a) bin(a, mod-2)%mod

int power(int x,int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return res;
}

int bin(int x,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}
vector<int> f;

// int nCr(int n, int r) {
//     // cout<<"#"<<"\n";
//     if(n<r) return 0;
//     if(n==r) return 1;
//     return (ft[n] *( mod_in((ft[r] * ft[n - r])%mod))%mod)%mod;
// }

// vector<int> adj[200001];
// bool vis[200001]={0};
// int c[200001], a[200001];
// int x;

// void dfs(int n, int l){
//     vis[n]=1;
//     if(adj[n].size()==1)
//     if(vis[a[n]]) x=a[n];
//     else dfs(a[n]);
// }
void solve(){
    double n;
    int ans=0, i=1;
    cin>>n;
    while(1){
        double k=n/pow(2,i);
        int m=k+0.5;
        if (m>=1) ans+=i*m;
        else break;
        i++;
    }
    cout<<ans<<endl;
}

signed main()
{
    fast
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define llu unsigned long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define PI 3.14159265
#define MOD 1000000007
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

using namespace std;

const ll inf = 1e18 + 42;

const ll M = 998244353;

ll power(ll x, ll y) {
	if (y == 0) return 1;
	if (y & 1) return (x * power(x, y - 1));
	ll t = power(x, y / 2);
	return (t * t);
}

const ll MAX = 1e6 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void ahShitHereWeGoAgain()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	for(ll i = 0; i < n; i++)
		cin >> a[i];
	sort(all(a));

	ll ans = 0;
	for(ll i = 0; i < n; i++)
	{
		ans = ans ^ a[i];
	}
	cout << ans << endl;

	// for(ll i = 1; i <= 1024; i++)
	// {
	// 	vector<ll> b;
	// 	for(ll j = 0; j < n; j++)
	// 	{
	// 		b.pb(a[j] ^ i);
	// 	}
	// 	sort(all(b));
	// 	if(a == b)
	// 	{
	// 		cout << i << endl;
	// 		return;
	// 	}
	// }
	// cout << -1 << endl;
}

int main()
{
	DESYNC
	ll t = 1;
	cin >> t;
	while (t--)
		ahShitHereWeGoAgain();
	return 0;
}