#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
const int INF = 0x3f3f3f3f;
const int MAXN = 200005;
using namespace std;
using ii = pair<int, int>;
using ll = long long int;
using vi = vector<ii>;
using graph = vector<vi>;
graph g;
int v[MAXN], ans[MAXN], sz[MAXN];
bool seen[MAXN];
int dfs(int u) {
    //printf("%d\n", u);
    seen[u] = 1;
    sz[u] = v[u];
    for (auto w : g[u]) if (!seen[w.F]) {
        dfs(w.F);
        if (w.S < 0) ans[-w.S] = -sz[w.F];
        else ans[w.S] = sz[w.F];
        sz[u] += sz[w.F];
    }
}
int main() {
    int n, m, k;
    scanf("%d", &n);
    g.assign(n+1, vi());
    int res = 0;
    for (int i = 1; i<=n; ++i) {
        scanf("%d", v+i);
        res += v[i];
    }
    if (res) {
        puts("Impossible");
        return 0;
    }
    scanf("%d", &m);
    for (int i = 1, u, w; i<=m; ++i) {
        scanf("%d %d", &u, &w);
        g[u].emplace_back(w, i);
        g[w].emplace_back(u, -i);
    }

    puts("Possible");
    dfs(1);
    for (int i = 1; i<=m; ++i) {
        printf("%d\n", ans[i]);
    }

}


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

const int MAXN = 200005;
struct Edge { int to, next, id; } edge[MAXN << 1];
int dep[MAXN], s[MAXN], head[MAXN], ans[MAXN], n, m, tot;
void addedge(int u, int v, int id) {
	edge[++tot] = (Edge) { v, head[u], id };
	head[u] = tot;
}
int sta[MAXN], cir[MAXN], arr[MAXN], fr[MAXN], to[MAXN], flag;
void dfs(int u, int fa) {
	dep[u] = dep[fa] + 1;
	sta[++tot] = u;
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (dep[v]) {
			edge[i].to = 0; continue;
			if (flag) { edge[i].to = 0; continue; }
			while (sta[tot] != v) {
				cir[sta[tot]] = 1;
				--tot;
			}
			cir[v] = flag = 1;
		} else dfs(v, u);
	}
	--tot;
}
void dfs1(int u, int fa) {
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (!v || v == fa || cir[v]) continue;
		dfs1(v, u);
		ans[edge[i].id] = s[v];
		if (fr[edge[i].id] == v) ans[edge[i].id] = -ans[edge[i].id];
		s[u] += s[v];
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", s + i);
	scanf("%d", &m);
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		addedge(u, v, i), addedge(v, u, i);
	}
	dfs(1, tot = 0);
	dfs1(1, 0);
	if (s[1]) return puts("Impossible") * 0;
	puts("Possible");
	for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
	return 0;
}


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

const int MAXN = 200005;
struct Edge { int to, next, id; } edge[MAXN << 1];
int dep[MAXN], s[MAXN], head[MAXN], ans[MAXN], n, m, tot;
void addedge(int u, int v, int id) {
	edge[++tot] = (Edge) { v, head[u], id };
	head[u] = tot;
}
int sta[MAXN], cir[MAXN], arr[MAXN], fr[MAXN], to[MAXN], flag;
void dfs(int u, int fa) {
	dep[u] = dep[fa] + 1;
	sta[++tot] = u;
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (dep[v]) {
			edge[i].to = 0; continue;
			if (flag) { edge[i].to = 0; continue; }
			while (sta[tot] != v) {
				cir[sta[tot]] = 1;
				--tot;
			}
			cir[v] = flag = 1;
		} else dfs(v, u);
	}
	--tot;
}
void dfs1(int u, int fa) {
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (!v || v == fa || cir[v]) continue;
		dfs1(v, u);
		ans[edge[i].id] = s[v];
		if (fr[edge[i].id] == v) ans[edge[i].id] = -ans[edge[i].id];
		s[u] += s[v];
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", s + i);
	scanf("%d", &m);
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		addedge(u, v, i), addedge(v, u, i);
		fr[i] = u, to[i] = v;
	}
	dfs(1, tot = 0);
	dfs1(1, 0);
	if (s[1]) return puts("Impossible") * 0;
	puts("Possible");
	for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin >> t;
    while(t--)
    {
        long long n;
        cin >> n;
        long long bits=64;
        //bits=(int)log2(n)+1;
            //bits=bits-1;
            //cout << bits << endl;
            long long count=0;
            long long i=0;
            while(bits--)
            {

                count=count+n/pow(2,i);
                //cout << count << endl;
                i++;
            }
        cout << count << endl;
    }

    return 0;
}


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

long long power(long long x,long long p){
    if(p==0)return 1;
    if(p==1)return x;
    if(p%2)
    return x*power(x,p-1);
    long long y=power(x,p/2);
    return y*y;

}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        long long n;
        cin >> n;
        long long bits;
        bits=(int)log2(n)+1;
            bits=bits-1;
            //cout << bits << endl;
            long long count=n;
            long long i=1;
            while(bits--)
            {

                count=count+n/power(2,i);
                //cout << count << endl;
                i++;
            }
        cout << count << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin >> t;
    while(t--)
    {
        long long n;
        cin >> n;
        long long bits=64;
        //bits=(int)log2(n)+1;
            bits=bits-1;
            //cout << bits << endl;
            long long count=0;
            long long i=0;
            while(bits--)
            {

                count=count+n/pow(2,i);
                //cout << count << endl;
                i++;
            }
        cout << count << endl;
    }

    return 0;
}


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

long long power(long long x,long long p){
    if(p==0)return 1;
    if(p==1)return x;
    if(p%2)
    return x*power(x,p-1);
    long long y=power(x,p/2);
    return y*y;

}

int main()
{
    long long t;
    cin >> t;
    while(t--)
    {
        long long n;
        cin >> n;
        //long long bits=64;
        //bits=(int)log2(n)+1;
            //bits=bits-1;
            //cout << bits << endl;
            long long count=0;
          //  long long i=0;
            for(long long i=0;;i++)
            {
                if((power(2,i))>n) break;
                count+=(n/(power(2,i)));
            }
        cout << count << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t;
    cin >> t;
    while(t--)
    {
        long long n;
        cin >> n;
        //long long bits=64;
        //bits=(int)log2(n)+1;
            //bits=bits-1;
            //cout << bits << endl;
            long long count=0;
          //  long long i=0;
            for(long long i=0;;i++)
            {
                if(pow(2,i)>n) break;
                count+=(n/(pow(2,i)));
            }
        cout << count << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        long long n;
        cin >> n;
        long long bits;
        bits=(int)log2(n)+1;
            bits=bits-1;
            //cout << bits << endl;
            long long count=n;
            long long i=1;
            while(bits--)
            {

                count=count+n/pow(2,i);
                //cout << count << endl;
                i++;
            }
        cout << count << endl;
    }

    return 0;
}


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

long long fast_power(long long base, long long power) {
    long long result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

int main()
{
    long long t;
    cin >> t;
    while(t--)
    {
        long long n;
        cin >> n;
        //long long bits=64;
        //bits=(int)log2(n)+1;
            //bits=bits-1;
            //cout << bits << endl;
            long long count=0;
          //  long long i=0;
            for(long long i=0;;i++)
            {
                if((fast_power(2,i))>n) break;
                count+=(n/(fast_power(2,i)));
            }
        cout << count << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert

typedef long double ld;
typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int y[100005];
ll powe(ll k)
{
    int i;
    ll ans=1;
    for(i=0;i<k;i++)
    ans*=2;
    return ans;
}
ll f(ll n)
{
    if(n<100005)
    {
        if(y[n]!=0)
        return y[n];
    }

    if(n==0)
    return 0;
    if(n==1)
    return 1;
    if(n==2)
    return 3;
    if(n==3)
    return 4;

    ll k=log2(n);
    ll p=powe(k);
     ll ans=k+1;
    ans+=f(p-1);
    ans+=f(n-p);
    if(n<100005)
    y[n]=ans;
    return ans;
}
void runcase()
{
    ll n;cin>>n;
    cout<<f(n)<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
runcase();
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert

typedef long double ld;
typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int y[9150625];
ll powe(ll k)
{
    int i;
    ll ans=1;
    for(i=0;i<k;i++)
    ans*=2;
    return ans;
}
ll f(ll n)
{
    if(n<9150625)
    {
        if(y[n]!=0)
        return y[n];
    }

    if(n==0)
    return 0;
    if(n==1)
    return 1;
    if(n==2)
    return 3;
    if(n==3)
    return 4;

    ll k=log2(n);
    ll p=powe(k);
     ll ans=k+1;
    ans+=f(p-1);
    ans+=f(n-p);
    if(n<9150625)
    y[n]=ans;
    return ans;
}
void runcase()
{
    ll n;cin>>n;
    cout<<f(n)<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
runcase();
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert

typedef long double ld;
typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int y[6150625];
ll powe(ll k)
{
    int i;
    ll ans=1;
    for(i=0;i<k;i++)
    ans*=2;
    return ans;
}
ll f(ll n)
{
    if(n<6150625)
    {
        if(y[n]!=0)
        return y[n];
    }

    if(n==0)
    return 0;
    if(n==1)
    return 1;
    if(n==2)
    return 3;
    if(n==3)
    return 4;

    ll k=log2(n);
    ll p=powe(k);
     ll ans=k+1;
    ans+=f(p-1);
    ans+=f(n-p);
    if(n<6150625)
    y[n]=ans;
    return ans;
}
void runcase()
{
    ll n;cin>>n;
    cout<<f(n)<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
runcase();
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert

typedef long double ld;
typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int y[600005];
ll powe(ll k)
{
    int i;
    ll ans=1;
    for(i=0;i<k;i++)
    ans*=2;
    return ans;
}
ll f(ll n)
{
    if(n<600005)
    {
        if(y[n]!=0)
        return y[n];
    }

    if(n==0)
    return 0;
    if(n==1)
    return 1;
    if(n==2)
    return 3;
    if(n==3)
    return 4;

    ll k=log2(n);
    ll p=powe(k);
     ll ans=k+1;
    ans+=f(p-1);
    ans+=f(n-p);
    if(n<600005)
    y[n]=ans;
    return ans;
}
void runcase()
{
    ll n;cin>>n;
    cout<<f(n)<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
runcase();
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert

typedef long double ld;
typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int y[100005];
ll powe(ll k)
{
    int i;
    ll ans=1;
    for(i=0;i<k;i++)
    ans*=2;
    return ans;
}
ll f(ll n)
{
    if(n==1)
    return 1;
    ll i;
    ll ans=0;
    ll z=1;
   ll k=log2(n);
   ll u=powe(k);

   u*=2;
    for(i=2;i<=u;i*=2)
    {
        ll p=n%i;
        ll q=n/i;
        if(p>=i/2)
        ans+=z;
        ans+=q*z;
        z++;
       // cout<<ans<<endl;

    }
    return ans;
}
void runcase()
{
    ll n;cin>>n;
    cout<<f(n)<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
runcase();
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert

typedef long double ld;
typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int y[1000005];
ll powe(ll k)
{
    int i;
    ll ans=1;
    for(i=0;i<k;i++)
    ans*=2;
    return ans;
}
ll f(ll n)
{
    if(n<1000005)
    {
        if(y[n]!=0)
        return y[n];
    }

    if(n==0)
    return 0;
    if(n==1)
    return 1;
    if(n==2)
    return 3;
    if(n==3)
    return 4;

    ll k=log2(n);
    ll p=powe(k);
     ll ans=k+1;
    ans+=f(p-1);
    ans+=f(n-p);
    if(n<1000005)
    y[n]=ans;
    return ans;
}
void runcase()
{
    ll n;cin>>n;
    cout<<f(n)<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
runcase();
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert

typedef long double ld;
typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int y[5000005];
ll powe(ll k)
{
    int i;
    ll ans=1;
    for(i=0;i<k;i++)
    ans*=2;
    return ans;
}
ll f(ll n)
{
    if(n<5000005)
    {
        if(y[n]!=0)
        return y[n];
    }

    if(n==0)
    return 0;
    if(n==1)
    return 1;
    if(n==2)
    return 3;
    if(n==3)
    return 4;

    ll k=log2(n);
    ll p=powe(k);
     ll ans=k+1;
    ans+=f(p-1);
    ans+=f(n-p);
    if(n<5000005)
    y[n]=ans;
    return ans;
}
void runcase()
{
    ll n;cin>>n;
    cout<<f(n)<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
runcase();
}


// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
#define int long long int
// Function to implement fast
// exponentiation
int binpow(int a, int b)
{
	int res = 1;

	while (b) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b /= 2;
	}
	return res;
}

// Function to return the value
// for powers of 2
int find(int x)
{
	if (x == 0)
		return 0;
	int p = log2(x);
	return binpow(2, p + 1) - 1;
}

// Function to convert N into binary
string getBinary(int n)
{
	// To store binary representation
	string ans = "";

	// Iterate each digit of n
	while (n) {
		int dig = n % 2;
		ans += to_string(dig);
		n /= 2;
	}

	// Return binary representation
	return ans;
}

// Function to find difference in bits
int totalCountDifference(int n)
{
	// Get binary representation
	string ans = getBinary(n);

	// total number of bit
	// differences from 0 to N
	int req = 0;

	// Iterate over each binary bit
	for (int i = 0; i < ans.size(); i++) {

		// If current bit is '1' then add
		// the count of current bit
		if (ans[i] == '1') {

			req += find(binpow(2, i));
		}
	}
	return req;
}

// Driver Code
int32_t main()
{
	// Given Number
	int t;
	cin>>t;
	while(t--)
    {
        int n;
        cin>>n;
	cout << totalCountDifference(n)<<endl;
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
    int n;
    cin>>n;
    if(n & (n-1) ==0)
    {
        int m=log2(n);
        int res=pow(2,m+1)-1;
        cout<<res;
        if(t>0)
            cout<<endl;
        continue;
    }
    int res=0;
    while(n>0)
    {
        int m=log2(n);
        n-=pow(2,m);
        res+=pow(2,m+1)-1;
    }
    cout<<res;
    if(t>0)
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
    int n;
    cin>>n;
    if(n & (n-1) ==0)
    {
        int m=log2(n);
        int res=pow(2,m+1)-1;
        cout<<res<<endl;
        continue;
    }
    int res=0;
    while(n>0)
    {
        int m=log2(n);
        n-=pow(2,m);
        res+=pow(2,m+1)-1;
    }
    cout<<res<<endl;
    }
    return 0;
}


// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;

// Function to implement fast
// exponentiation
int binpow(int a, int b)
{
	int res = 1;

	while (b) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b /= 2;
	}
	return res;
}

// Function to return the value
// for powers of 2
int find(int x)
{
	if (x == 0)
		return 0;
	int p = log2(x);
	return binpow(2, p + 1) - 1;
}

// Function to convert N into binary
string getBinary(int n)
{
	// To store binary representation
	string ans = "";

	// Iterate each digit of n
	while (n) {
		int dig = n % 2;
		ans += to_string(dig);
		n /= 2;
	}

	// Return binary representation
	return ans;
}

// Function to find difference in bits
int totalCountDifference(int n)
{
	// Get binary representation
	string ans = getBinary(n);

	// total number of bit
	// differences from 0 to N
	int req = 0;

	// Iterate over each binary bit
	for (int i = 0; i < ans.size(); i++) {

		// If current bit is '1' then add
		// the count of current bit
		if (ans[i] == '1') {

			req += find(binpow(2, i));
		}
	}
	return req;
}

// Driver Code
int main()
{
	// Given Number
	int t;
	cin>>t;
	while(t--)
    {
        int n;
        cin>>n;
	cout << totalCountDifference(n)<<endl;
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fo(i,a,b) for(ll i=a;i<b;i++)
#define int unsigned long long int
#define pi 3.141592653589793238
#define double long double
int32_t main()
{
    io;
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int v[]={1,2,1,3,1,2,1};
        int sum[7];
        sum[0]=v[0];
        for(int i=1;i<7;i++)
        {
            sum[i]=sum[i-1]+v[i];
        }
        if(n<8)
        {
            cout<<sum[n-1]<<endl;
            continue;
        }
        /*for(int i=1;i<temp.size();i++)
        {
            int dif=temp[i]-temp[i-1];
            int v1=dif/8;
            res+=v1*sum[6];
            res+=log2(temp[i])+1;
        }
        int dif=n-temp[temp.size()-1];
        if(dif>0)
            res+=sum[dif-1];
        cout<<res<<endl;*/
        int len=log2(n);
        int res=sum[6]+4;
        for(int i=4;i<=len;i++)
        {
            res+=i+1;
            int v1=(pow(2,i)-pow(2,i-1))/8;
            res+=v1*sum[6];
        }
        int l=n-pow(2,len);
        int v1=l/7;
        int v2=l%7;
        res+=v1*sum[6];
        if(v2>0)
            res+=sum[v2-1];
        cout<<res<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ull a;cin>>a;
    ull ans=0;
    while(a>=1){
        ull k = log2(a);
        ans += (ull)power(2,k+1)-1;
        a = a-(ull)power(2,k);
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2(a);ll m = (ll)1<<(k);
        ans += (ll)2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2l(a);ll m = pow(2,k);
        ans += (ll)2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    unsigned ll a;cin>>a;
    unsigned ll ans=0;
    while(a>=1){
        unsigned ll k = log2(a);
        ans += (unsigned ll)power(2,k+1)-1;
        a = a-(unsigned ll)power(2,k);
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2(a);
        ans += (ll)pow(2,k+1)-1;
        a = a-(ll)pow(2,k);
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2(a);ll m = (ll)2<<(k-1);
        ans += (ll)2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2(a);
        ans += (ll)power(2,k+1)-1;
        a = a-(ll)power(2,k);
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2(a);ull m = (ull)pow(2,k);
        ans += 2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ull a;cin>>a;
    ull ans=0;
    while(a>=1){
        ull k = log2(a), m = (ull)power(2,k);
        ans += 2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2(a);ll m = pow(2,k);
        ans += (ll)2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2(a);ll m = (ll)2<<k;
        ans += (ll)2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;
using ull = unsigned long long;
#define loop(i,a,b) for (int i = (a); i < (b); i++)
#define rev(i,b,a) for (int i = (b); i > (a); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void getPrimes(int n,  vector<int>& ans)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    loop(i,2,prime.size()){
        if(prime[i])ans.pb(i);
    }

}

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

void solve(){
    ll a;cin>>a;
    ll ans=0;
    while(a>=1){
        ll k = log2l(a);ll m = (ll)1<<(k);
        ans += (ll)2*m -1;
        a = a-m;
    }
    if(a==1)ans++;
    cout<<ans<<endl;
}

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


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

typedef long long ll;
typedef long int lint;

vector<ll> sum(60, 0);

ll solve(ll n)
{
	if(n <= 2) return n;
	ll power_2 = 0;
	ll x = n+1;
	while(x > 1)
	{
		power_2++;
		x /= 2;
	}

	if(pow(2, power_2) - 1 == n) return sum[power_2];
	else return sum[power_2] + (power_2 + 1) + solve(n - pow(2, power_2));
}

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

	sum[1] = 1;
	for(int i = 2; i <= 59; i++) sum[i] = 2*sum[i-1] + i;

	int t;
	cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		cout << solve(n) << '\n';
	}
	return 0;
}


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

typedef long long ll;
typedef long int lint;

vector<ll> sum(60, 0);

ll solve(ll n)
{
	if(n <= 1) return n;
	if(n == 2) return 3;
	ll p = 0;
	ll x = n+1;
	while(x > 1)
	{
		p++;
		x /= 2;
	}

	if(pow(2, p) - 1 == n) return sum[p];
	else return sum[p] + (p + 1) + solve(n - pow(2, p));
}

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

	sum[1] = 1;
	for(int i = 2; i <= 59; i++) sum[i] = 2*sum[i-1] + i;

	int t;
	cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		cout << solve(n) << '\n';
	}
	return 0;
}


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

typedef long long ll;
typedef long int lint;

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

	int t;
	cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		n *= 2;
		ll k = 2, ans = 0;
		while(n >= k)
		{
			ans += n/k;
			k *= 2;
		}

		cout << ans << endl;
	}
	return 0;
}


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

typedef long long ll;
typedef long int lint;

vector<ll> sum(81, 0);

ll solve(ll n)
{
	if(n <= 0) return 0;
	if(n == 1) return 1;
	if(n == 2) return 3;

	ll p = 0;
	ll x = n+1;
	while(x > 1)
	{
		p++;
		x /= 2;
	}

	if(pow(2, p) - 1 == n) return sum[p];
	else return sum[p] + (p + 1) + solve(n - pow(2, p));
}

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

	sum[1] = 1;
	for(int i = 2; i <= 80; i++) sum[i] = 2*sum[i-1] + i;

	int t;
	cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		cout << solve(n) << '\n';
	}
	return 0;
}


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

typedef long long ll;
typedef long int lint;

vector<ll> sum(65, 0);

ll solve(ll n)
{
	if(n <= 1) return n;
	if(n == 2) return 3;

	ll p = 0;
	ll x = n+1;
	while(x > 1)
	{
		p++;
		x /= 2;
	}

	if(pow(2, p) - 1 == n) return sum[p];
	else return sum[p] + (p + 1) + solve(n - pow(2, p));
}

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

	sum[1] = 1;
	for(int i = 2; i <= 64; i++) sum[i] = 2*sum[i-1] + i;

	int t;
	cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		cout << solve(n) << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
const double pi=3.141592653;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";
// ll gcd(ll a,ll b){
//     if(a==0)    return b;
//     gcd(b%a,a);
// }

int main() {
    int t;
    cin>>t;
    ull n,i,m,a,b,l=0,g,ans;

    while(t--){ans=l=b=0;
        cin>>n;
        ans+=ceil(n/2.0);
        n-=ans;l=2;
        while(n){
            b=ceil(n/2.0);
            a=l*1LL*b;
            ans+=a;
            n-=b;
            l++;
        }
        cout<<ans<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
const double pi=3.141592653;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";
// ll gcd(ll a,ll b){
//     if(a==0)    return b;
//     gcd(b%a,a);
// }

int main() {
    int t;
    cin>>t;
    ll n,i,m,a,b,l=0,g,ans;

    while(t--){ans=b=0;
        cin>>n;m=n;
        ans=ceil(n/2.0);
        n-=ans;l=2;
        while(l<log2(m)+2){
            b=ceil(n/2.0);
            a=l*1LL*b;
            ans+=a;
            n-=b;
            l++;
        }
        cout<<ans<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
const double pi=3.141592653;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";
// ll gcd(ll a,ll b){
//     if(a==0)    return b;
//     gcd(b%a,a);
// }

int main() {
    int t;
    cin>>t;
    ll n,i,m,a,b,l=0,g,ans;

    while(t--){ans=l=0;
        cin>>n;
        ans+=ceil(n/2.0);
        n-=ans;l=2;
        while(n>0){
            b=ceil(n/2.0);
            ans+=l*1LL*b;
            n-=b;
            l++;
        }
        cout<<ans<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
const double pi=3.141592653;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";
// ll gcd(ll a,ll b){
//     if(a==0)    return b;
//     gcd(b%a,a);
// }

int main() {
    int t;
    cin>>t;
    ll n,i,m,a,b,l=0,g,ans;

    while(t--){ans=l=b=a=0;
        cin>>n;
        ans=ceil(n/2.0);
        n-=ans;l=2;
        while(n>0){
            b=ceil(n/2.0);
            a=l*b;
            ans+=a;
            n-=b;
            l++;
        }
        cout<<ans<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
const double pi=3.141592653;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";
// ll gcd(ll a,ll b){
//     if(a==0)    return b;
//     gcd(b%a,a);
// }

int main() {
    int t;
    cin>>t;
    ll n,i,m,a,b,l=0,g,ans;

    while(t--){ans=b=0;
        cin>>n;m=n;
        ans=(n+1)/2;
        n-=ans;l=2;
        // cout<<ans<<" "<<n<<" | ";
        while(n){
            b=(n+1)/2;
            // cout<<b<<' '<<l<<" | ";
            a=l*1LL*b;
            ans+=a;
            n-=b;
            l++;
            // cout<<"ans: "<<ans<<"; ";
        }
        cout<<ans<<endl;
    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
ll arr[64],arr1[64],n;

void solve(ll p,ll *sum)
{

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

    ll p;
    arr[1] = 1;
    for(p=2;p<64;p++)
     arr[p] = p + 2*arr[p-1];
    for(p=2;p<64;p++)
    arr1[p] = arr[p-1] + p;
    arr1[1] = 1;
    ll t;
    cin>>t;
    while(t--)
    {
        ll sum = 0,i;
        cin>>n;
        ll bits = (ll)log2(n) + 1;
        for(i=0;i<bits;i++)
        {
            if((n&(1LL<<i))!=0)
            sum+= arr1[i+1];
        }
        cout<<sum<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
ll arr[58],n;
set<ll> vik;
void solve(ll p)
{
   if(p==1)
   {
       cout<<1;
       return;
   }
   ll sum=0;
   do{
   ll bits = (ll)log2(p) + 1;
   if(bits==1)
   {
       if(p==1)
       sum++;
       break;
   }

   (sum) += arr[bits-1];
   (sum) += bits;
   ll newn = (1LL<<(bits-1)) - 1;
   p = (p&newn);
   }while(p!=0);
  cout<<sum;

  vik.insert(sum);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll p;
    arr[1] = 1;
    for(p=2;p<64;p++)
     arr[p] = p + 2*arr[p-1];

    ll t = 1;
    cin>>t;
    while(t--)
    {

        cin>>n;
        //cout<<n<<endl;
        set<ll>::iterator it = vik.find(n);
        if(it==vik.end())
        solve(n);
        else
        cout<<(*it);
        //cout<<sum;
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
ll arr[58],n;

void solve(ll p,ll *sum)
{
   if(p==0)
   return;

   ll bits = (ll)log2(p) + 1;
   if(bits==1)
   {
       if(p==1)
       (*sum)++;

       return;
   }

   (*sum) += arr[bits-1];
   (*sum) += bits;
   ll newn = (1LL<<(bits-1)) - 1;
   newn = (p&newn);
   solve(newn,sum);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll p;
    arr[1] = 1;
    for(p=2;p<64;p++)
     arr[p] = p + 2*arr[p-1];
    map<ll,ll> vik;
    map<ll,ll>::iterator it;
    set<ll> ben;
    ll t;
    cin>>t;
    while(t--)
    {
        ll sum = 0;
        cin>>n;

       it = vik.find(n);
       if(it==vik.end())
        {
            solve(n,&sum);
            cout<<sum;
            ll s = sum;
            vik.insert({n,sum});
        }
        else
         cout<<(it->second);

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
ll arr[58],n;
void solve(ll p)
{
   if(p==1)
   {
       cout<<1;
       return;
   }
   ll sum=0;
   do{
   ll bits = (ll)log2(p) + 1;
   if(bits==1)
   {
       if(p==1)
       sum++;
       break;
   }

   (sum) += arr[bits-1];
   (sum) += bits;
   ll newn = (1LL<<(bits-1)) - 1;
   p = (p&newn);
   }while(p!=0);
  cout<<sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll p;
    arr[1] = 1;
    for(p=2;p<64;p++)
     arr[p] = p + 2*arr[p-1];

    ll t = 1;
    cin>>t;
    while(t--)
    {

        cin>>n;
        //cout<<n<<endl;
        solve(n);
        //cout<<sum;
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
ll arr[58],n;
void solve(ll p,ll *sum)
{
   if(p==0)
   return;

   ll bits = (ll)log2(p) + 1;
   if(bits==1)
   {
       if(p==1)
       (*sum)++;

       return;
   }

   (*sum) += arr[bits-1];
   (*sum) += bits;
   ll newn = (1LL<<(bits-1)) - 1;
   newn = (p&newn);
   solve(newn,sum);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll p;
    arr[1] = 1;
    for(p=2;p<58;p++)
     arr[p] = p + 2*arr[p-1];

    ll t = 1;
    cin>>t;
    while(t--)
    {
        ll sum = 0;
        cin>>n;
        //cout<<n<<endl;
        solve(n,&sum);
        cout<<sum;
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
ll arr[58],n;
set<ll> vik;
void solve(ll p)
{
   if(p==1)
   {
       cout<<1;
       return;
   }
   ll sum=0;
   do{
   ll bits = (ll)log2(p) + 1;
   if(bits==1)
   {
       if(p==1)
       sum++;
       break;
   }

   (sum) += arr[bits-1];
   (sum) += bits;
   ll newn = (1LL<<(bits-1)) - 1;
   p = (p&newn);
   }while(p!=0);
  cout<<sum;

  vik.insert(sum);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll z;
    arr[1] = 1;
    for(z=2;z<64;z++)
     arr[z] = z + 2*arr[z-1];

    ll t = 1;
    cin>>t;
    while(t--)
    {

        cin>>n;
        //cout<<n<<endl;
        set<ll>::iterator it = vik.find(n);
        if(it==vik.end())
        solve(n);
        else
        cout<<(*it);
        //cout<<sum;
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
ll arr[58],n;
void solve(ll p,ll *sum)
{
   if(p==0)
   return;

   ll bits = (ll)log2(p) + 1;
   if(bits==1)
   {
       if(p==1)
       (*sum)++;

       return;
   }

   (*sum) += arr[bits-1];
   (*sum) += bits;
   ll newn = (1LL<<(bits-1)) - 1;
   newn = (p&newn);
   solve(newn,sum);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll p;
    arr[1] = 1;
    for(p=2;p<64;p++)
     arr[p] = p + 2*arr[p-1];

    ll t = 1;
    cin>>t;
    while(t--)
    {
        ll sum = 0;
        cin>>n;
        //cout<<n<<endl;
        solve(n,&sum);
        cout<<sum;
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//const double pi=acos(-1.0);
#define mod 1000000007
#define forn(i,k,n) for(ll i=k;i<n;i++)
#define fornr(i,k,k1) for(ll i=k;i>=k1;i--)
#define v(ll) vector<ll>
#define vl(a,n,ll,k) vector<ll> a(n,k)
#define vli(a,n) vector<ll> a(n)
#define init(a,n) vector<ll> a(n);forn(i,0,n)cin>>a[i]
#define vll(a,n,m,ll,k) vector<vector<ll>> a(n,vector<ll>(m,k))
#define mp(a,ll,ll1) map<ll,ll1> a
#define st(a,ll) set<ll> a
#define mpa make_pair
#define pr pair<ll,ll>
#define pb push_back
#define MAX 1000000
#define ed '\n'
#define fileTake ifstream cin("input.txt");ofstream cout("output.txt");
#define sortv(a) sort(a.begin(),a.end())
#define sorta(a,n) sort(a,a+n)
#define yeah "YES"
#define nil "NO"
#define All(x) x.begin(),x.end()
#define remDup(a) a.erase(unique(All(a)),a.end())
#define N 100

void swap(ll &x,ll &y)
{
	x=x^y;
	y=x^y;
	x=x^y;
}

template<typename T>
void print(T a){for(auto i=a.begin();i!=a.end();i++)cout<<*i<<" ";cout<<endl;}
bool isVowel(char c)
{
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')return true;
	return false;
}

void sync(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main(){
	sync();
	ll t;
	cin>>t;
	for(ll testcase=1;testcase<=t;testcase++){
	ll n;
	cin>>n;
	if(n==1)
	{
		cout<<1<<endl;
	}
	else
	{
		ll o=2;
		ll ans=0;
		while(n>0)
		{
		ll x=floor(log2(n));
		ll y=pow(2,x);
		ans+=(2*y-1);
		if(y==n)
		{
			break;
			}
		else
		{
			n=n^y;
		}
		}
		cout<<ans<<endl;
	}
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//const double pi=acos(-1.0);
#define mod 1000000007
#define forn(i,k,n) for(ll i=k;i<n;i++)
#define fornr(i,k,k1) for(ll i=k;i>=k1;i--)
#define v(ll) vector<ll>
#define vl(a,n,ll,k) vector<ll> a(n,k)
#define vli(a,n) vector<ll> a(n)
#define init(a,n) vector<ll> a(n);forn(i,0,n)cin>>a[i]
#define vll(a,n,m,ll,k) vector<vector<ll>> a(n,vector<ll>(m,k))
#define mp(a,ll,ll1) map<ll,ll1> a
#define st(a,ll) set<ll> a
#define mpa make_pair
#define pr pair<ll,ll>
#define pb push_back
#define MAX 1000000
#define ed '\n'
#define fileTake ifstream cin("input.txt");ofstream cout("output.txt");
#define sortv(a) sort(a.begin(),a.end())
#define sorta(a,n) sort(a,a+n)
#define yeah "YES"
#define nil "NO"
#define All(x) x.begin(),x.end()
#define remDup(a) a.erase(unique(All(a)),a.end())
#define N 100

void swap(ll &x,ll &y)
{
	x=x^y;
	y=x^y;
	x=x^y;
}

template<typename T>
void print(T a){for(auto i=a.begin();i!=a.end();i++)cout<<*i<<" ";cout<<endl;}
bool isVowel(char c)
{
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')return true;
	return false;
}

void sync(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main(){
	sync();
	ll t;
	cin>>t;
	for(ll testcase=1;testcase<=t;testcase++){
	ll n;
	cin>>n;
	if(n==1)
	{
		cout<<1<<endl;
	}
	else
	{
		ll o=2;
		ll ans=0;
		while(n>0)
		{
		ll x=floor(log2(n));
		ll y=pow(2,x);
		ans+=(2*y-1);
		if(y==n)
		{
			break;
			}
		else
		{
			n=n-y;
		}
		}
		cout<<ans<<endl;
	}
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//const double pi=acos(-1.0);
#define mod 1000000007
#define forn(i,k,n) for(ll i=k;i<n;i++)
#define fornr(i,k,k1) for(ll i=k;i>=k1;i--)
#define v(ll) vector<ll>
#define vl(a,n,ll,k) vector<ll> a(n,k)
#define vli(a,n) vector<ll> a(n)
#define init(a,n) vector<ll> a(n);forn(i,0,n)cin>>a[i]
#define vll(a,n,m,ll,k) vector<vector<ll>> a(n,vector<ll>(m,k))
#define mp(a,ll,ll1) map<ll,ll1> a
#define st(a,ll) set<ll> a
#define mpa make_pair
#define pr pair<ll,ll>
#define pb push_back
#define MAX 1000000
#define ed '\n'
#define fileTake ifstream cin("input.txt");ofstream cout("output.txt");
#define sortv(a) sort(a.begin(),a.end())
#define sorta(a,n) sort(a,a+n)
#define yeah "YES"
#define nil "NO"
#define All(x) x.begin(),x.end()
#define remDup(a) a.erase(unique(All(a)),a.end())
#define N 100

void swap(ll &x,ll &y)
{
	x=x^y;
	y=x^y;
	x=x^y;
}

template<typename T>
void print(T a){for(auto i=a.begin();i!=a.end();i++)cout<<*i<<" ";cout<<endl;}
bool isVowel(char c)
{
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')return true;
	return false;
}

void sync(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main(){
	sync();
	ll t;
	cin>>t;
	for(ll testcase=1;testcase<=t;testcase++){
	ll n;
	cin>>n;
	if(n==1)
	{
		cout<<1<<endl;
	}
	else
	{

		ll ans=0;
		ll o=1;
		while(n>0)
		{
			if(n%2)
			{
				ans+=(2*o-1);
			}
			o*=2;
			n/=2;
		}
		cout<<ans<<endl;
	}
	}
	}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//const double pi=acos(-1.0);
#define mod 1000000007
#define forn(i,k,n) for(ll i=k;i<n;i++)
#define fornr(i,k,k1) for(ll i=k;i>=k1;i--)
#define v(ll) vector<ll>
#define vl(a,n,ll,k) vector<ll> a(n,k)
#define vli(a,n) vector<ll> a(n)
#define init(a,n) vector<ll> a(n);forn(i,0,n)cin>>a[i]
#define vll(a,n,m,ll,k) vector<vector<ll>> a(n,vector<ll>(m,k))
#define mp(a,ll,ll1) map<ll,ll1> a
#define st(a,ll) set<ll> a
#define mpa make_pair
#define pr pair<ll,ll>
#define pb push_back
#define MAX 1000000
#define ed '\n'
#define fileTake ifstream cin("input.txt");ofstream cout("output.txt");
#define sortv(a) sort(a.begin(),a.end())
#define sorta(a,n) sort(a,a+n)
#define yeah "YES"
#define nil "NO"
#define All(x) x.begin(),x.end()
#define remDup(a) a.erase(unique(All(a)),a.end())
#define N 100

void swap(ll &x,ll &y)
{
	x=x^y;
	y=x^y;
	x=x^y;
}

template<typename T>
void print(T a){for(auto i=a.begin();i!=a.end();i++)cout<<*i<<" ";cout<<endl;}
bool isVowel(char c)
{
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')return true;
	return false;
}

void sync(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main(){
	sync();
	ll t;
	cin>>t;
	for(ll testcase=1;testcase<=t;testcase++){
	ll n;
	cin>>n;
	if(n==1)
	{
		cout<<1<<endl;
	}
	else
	{
		ll o=2;
		ll ans=0;
		while(n>0)
		{
		ll x=floor(log2(n));
		ll y=pow(2,x);
		ans+=(2*y-1);
		if(y==n)
		{
			break;
			}
		else
		{
			n=n/2;
		}
		}
		cout<<ans<<endl;
	}
	}
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lli long long int
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       lli n;
        cin>>n;
        if(n==0||n==1)
        {
            cout<<n<<endl;
            continue;
        }
       lli x=(lli)(log2(n));
       lli ans=0;
       lli cnt=0;
       while(cnt<=x)
       {
           ans+=(pow(2,cnt));
           cnt++;
       }
       lli val=pow(2,x);
       lli  diff=n-val;
       if(diff==0)
       cout<<ans<<endl;
       else
       {
           while(diff!=0&&diff!=1)
           {
               x=(lli)(log2(diff));
                cnt=0;
                while(cnt<=x)
                {
                    ans+=(pow(2,cnt));
                    cnt++;
                }
                diff=diff-pow(2,x);
           }
           if(diff==1)
            ans++;
           cout<<ans<<endl;
       }

    }
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lli long long int
using namespace std;
lli countSetBits(lli n)
{
    // base case
    if (n == 0)
        return 0;

    else

        // if last bit set add 1 else add 0
        return (n & 1) + countSetBits(n >> 1);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       lli n;
        cin>>n;
       lli x=floor(log2(n));
       lli ans=0;
       lli cnt=0;
       while(cnt<=x)
       {
           ans+=(pow(2,cnt));
           cnt++;
       }
       lli val=pow(2,x);
       lli  diff=n-val;
       if(diff==0)
       cout<<ans<<endl;
       else
       {
           while(diff!=0&&diff!=1)
           {
               x=floor(log2(diff));
                cnt=0;
                while(cnt<=x)
                {
                    ans+=(pow(2,cnt));
                    cnt++;
                }
                diff=diff-pow(2,x);
           }
           if(diff==1)
            ans++;
           cout<<ans<<endl;
       }

    }
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lli long long int
using namespace std;
lli countSetBits(lli n)
{
    // base case
    if (n == 0)
        return 0;

    else

        // if last bit set add 1 else add 0
        return (n & 1) + countSetBits(n >> 1);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       lli n;
        cin>>n;
       lli x=floor(log2(n));
       lli ans=0;
       lli cnt=0;
       while(cnt<=x)
       {
           ans+=(pow(2,cnt));
           cnt++;
       }
       lli val=pow(2,x);
       lli  diff=n-val;
       if(diff==0)
       cout<<ans<<endl;
       else
       {
           while(diff!=0)
           {
               x=floor(log2(diff));
                cnt=0;
                while(cnt<=x)
                {
                    ans+=(pow(2,cnt));
                    cnt++;
                }
                diff=diff-pow(2,x);
           }
           cout<<ans<<endl;
       }

    }
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
int main()
{
	    int t;
		cin>>t;
          while(t--)
        {
            lli m;
            cin >> m;
            lli cnt = 0;
            while(m)
            {
                cnt+=m;
                m /= 2;
	    }
            cout<<cnt<<endl;
        }

}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lli long long int
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       lli n;
        cin>>n;
       lli x=(lli)(log2(n));
       lli ans=0;
       lli cnt=0;
       while(cnt<=x)
       {
           ans+=(pow(2,cnt));
           cnt++;
       }
       lli val=pow(2,x);
       lli  diff=n-val;
       if(diff==0)
       cout<<ans<<endl;
       else
       {
           while(diff!=0&&diff!=1)
           {
               x=(lli)(log2(diff));
                cnt=0;
                while(cnt<=x)
                {
                    ans+=(pow(2,cnt));
                    cnt++;
                }
                diff=diff-pow(2,x);
           }
           if(diff==1)
            ans++;
           cout<<ans<<endl;
       }

    }
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lli long long int
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       lli n;
        cin>>n;
        if(n==0||n==1)
            return n;
       lli x=(lli)(log2(n));
       lli ans=0;
       lli cnt=0;
       while(cnt<=x)
       {
           ans+=(pow(2,cnt));
           cnt++;
       }
       lli val=pow(2,x);
       lli  diff=n-val;
       if(diff==0)
       cout<<ans<<endl;
       else
       {
           while(diff!=0&&diff!=1)
           {
               x=(lli)(log2(diff));
                cnt=0;
                while(cnt<=x)
                {
                    ans+=(pow(2,cnt));
                    cnt++;
                }
                diff=diff-pow(2,x);
           }
           if(diff==1)
            ans++;
           cout<<ans<<endl;
       }

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
    ll t,i,j,n,a,b,k,w;
    cin>>t;
    ll power[61];
    power[0]=1;
    for(i=1;i<=60;i++)
    power[i]=2*power[i-1];
    while(t--){
        cin>>n;
        ll ans=0;
        for(i=1;i<=59;i++){
            double val= (double) n/power[i];
            ll val1=val;
            double val2=(double) val1+0.5;
            if(val>=val2)
            val1++;

            if(val1){
                ans+=i*val1;
            }
            if(val1==0)
            break;
        }
        cout<<ans<<"\n";

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
    ll t,i,j,n,a,b,k,w;
    cin>>t;
    ll power[61];
    power[0]=1;
    for(i=1;i<=60;i++)
    power[i]=2*power[i-1];
    while(t--){
        cin>>n;
        ll ans=0;
        for(i=1;i<=59;i++){
            ll val1=n/power[i];
            if(val1*power[i]+power[i-1]<=n)
            val1++;

            if(val1){
                ans+=i*val1;
            }
            if(val1==0)
            break;
        }
        cout<<ans<<"\n";

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
    ll t,i,j,n,a,b,k,w;
    cin>>t;
    ll power[71];
    power[0]=1;
    for(i=1;i<=62;i++)
    power[i]=2*power[i-1];
    while(t--){
        cin>>n;
        ll ans=0;
        for(i=1;i<=62;i++){
            ll val1=n/power[i];
            if(val1*power[i]+power[i-1]<=n)
            val1++;

            if(val1){
                ans+=i*val1;
            }
            if(val1==0)
            break;
        }
        cout<<ans<<"\n";

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
    ll t,i,j,n,a,b,k,w;
    cin>>t;
    ll power[61];
    power[0]=1;
    for(i=1;i<=60;i++)
    power[i]=2*power[i-1];
    while(t--){
        cin>>n;
        ll ans=0;
        for(i=1;i<=60;i++){
            double val= (double) n/power[i];
            ll val1=val;
            double val2=(double) val1+0.5;
            if(val>=val2)
            val1++;

            if(val1){
                ans+=i*val1;
            }
            if(val1==0)
            break;
        }
        cout<<ans<<"\n";

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
    ll t,i,j,n,a,b,k,w;
    cin>>t;
    while(t--){
        cin>>n;
        ll ans=0;
        for(i=1;i<=60;i++){
            double val= n/pow(2,i);
            ll val1=val;
            double val2=(double) val1+0.5;
            if(val>=val2)
            val1++;

            if(val1){
                ans+=i*val1;
            }
            if(val1==0)
            break;
        }
        cout<<ans<<"\n";

    }
    return 0;
}


#include "bits/stdc++.h"
      #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      #define ld long int
      #define all(A) begin(A) , end(A)
      #define rep(i , a , b)  for(lld i = a; i < b ; i++)
      #define rep1(i , a , b) for(lld i = a ; i >= b ; i--)
      #define lld long long int
      #define ulld unsigned long long int
      #define input lld* a = new lld [n]
      #define input1 lld* b = new lld [n]
      #define vec vector < lld >
      #define sz(x) x.size()
      #define pb push_back
      #define ss second
      #define ff first
      #define inf 999999999999999999
      #define fin -999999999999999999
      #define mod 1000000007
      #define umap unordered_map
      #define mpp make_pair
      #define finish(x) cout << v << " ";
      #define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

      using namespace std;

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

lld high(lld n)
{

   lld p = (lld)log2(n);
   // return (lld)pow(2, p);
   return p;
}

  void beast(){
      lld a;cin>>a;
      lld temp=a;
      lld x = a;
      if(a == 1){
          cout<<"1"<<endl;return;
      }
      if(a > 1){
          while(a >= 1){
              lld i=1;
              lld j = high(a);

      a = a - (lld)(pow(2,j));
      x += pow(2,j+1)-1;
          }
          cout<< x - temp<<endl;return;
      }

  }

  signed main(){
    start();
    FAST_IO;
    lld t = 1;
    cin >> t;
    while(t--){
       beast();
    }
  }

  //  c0ded by :
  // - - - - - - - - - - - - - - - - - - - - - - beast


#include "bits/stdc++.h"
      #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      #define ld long int
      #define all(A) begin(A) , end(A)
      #define rep(i , a , b)  for(lld i = a; i < b ; i++)
      #define rep1(i , a , b) for(lld i = a ; i >= b ; i--)
      #define lld long long int
      #define ulld unsigned long long int
      #define input lld* a = new lld [n]
      #define input1 lld* b = new lld [n]
      #define vec vector < lld >
      #define sz(x) x.size()
      #define pb push_back
      #define ss second
      #define ff first
      #define inf 999999999999999999
      #define fin -999999999999999999
      #define mod 1000000007
      #define umap unordered_map
      #define mpp make_pair
      #define finish(x) cout << v << " ";
      #define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

      using namespace std;

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

lld high(lld n)
{

   lld p = (lld)log(n)/log(2);
   // return (lld)pow(2, p);
   return p;
}

  void beast(){
      lld a;cin>>a;
      lld temp=a;
      lld x = 0;
      for(int i = 0; i < 60; ++i)
		if(a & (1LL << i))
			x += (1LL << (i + 1)) - 1;
      cout<<x<<endl;
  }

  signed main(){
    start();
    FAST_IO;
    lld t = 1;
    cin >> t;
    while(t--){
       beast();
    }
  }

  //  c0ded by :
  // - - - - - - - - - - - - - - - - - - - - - - beast


      #include "bits/stdc++.h"
      #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      #define ld long int
      #define all(A) begin(A) , end(A)
      #define rep(i , a , b)  for(lld i = a; i < b ; i++)
      #define rep1(i , a , b) for(lld i = a ; i >= b ; i--)
      #define lld long long int
      #define ulld unsigned long long int
      #define input lld* a = new lld [n]
      #define input1 lld* b = new lld [n]
      #define vec vector < lld >
      #define sz(x) x.size()
      #define pb push_back
      #define ss second
      #define ff first
      #define inf 999999999999999999
      #define fin -999999999999999999
      #define mod 1000000007
      #define umap unordered_map
      #define mpp make_pair
      #define finish(x) cout << v << " ";
      #define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

      using namespace std;

      void start()
      {
        #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin) ;
        freopen("output.txt" , "w" , stdout) ;
        #endif
      }
  void beast(){
      lld a;cin>>a;
      lld temp=a;
      lld x=a;lld ans=0;
      if(a == 1){
          cout<<"1"<<endl;return;
      }
      if(a>1){
          while(a>1){
              int i=1;int j;
              while(pow(2,i)<a){
          j=i;i++;
      }
      a=a-pow(2,j);x+=pow(2,j+1)-1;
          }
          cout<<x+1-temp<<endl;return;
      }

  }

  signed main(){
    start();
    FAST_IO;
    lld t = 1;
    cin >> t;
    while(t--){
       beast();
    }
  }

  //  c0ded by :
  // - - - - - - - - - - - - - - - - - - - - - - beast


      #include "bits/stdc++.h"
      #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      #define ld long int
      #define all(A) begin(A) , end(A)
      #define rep(i , a , b)  for(lld i = a; i < b ; i++)
      #define rep1(i , a , b) for(lld i = a ; i >= b ; i--)
      #define lld long long int
      #define ulld unsigned long long int
      #define input lld* a = new lld [n]
      #define input1 lld* b = new lld [n]
      #define vec vector < lld >
      #define sz(x) x.size()
      #define pb push_back
      #define ss second
      #define ff first
      #define inf 999999999999999999
      #define fin -999999999999999999
      #define mod 1000000007
      #define umap unordered_map
      #define mpp make_pair
      #define finish(x) cout << v << " ";
      #define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

      using namespace std;

      void start()
      {
        #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin) ;
        freopen("output.txt" , "w" , stdout) ;
        #endif
      }
  void beast(){
      lld a;cin>>a;
      lld temp=a;
      lld x=a;
      if(a == 1){
          cout<<"1"<<endl;return;
      }
      if(a>1){
          while(a>=1){
              int i=1;int j=0;
              while(pow(2,i)<=a){
          j=i;i++;
      }
      a=a-pow(2,j);
      x+=pow(2,j+1)-1;
          }
          cout<<x-temp<<endl;return;
      }

  }

  signed main(){
    start();
    FAST_IO;
    lld t = 1;
    cin >> t;
    while(t--){
       beast();
    }
  }

  //  c0ded by :
  // - - - - - - - - - - - - - - - - - - - - - - beast


#include "bits/stdc++.h"
      #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      #define ld long int
      #define all(A) begin(A) , end(A)
      #define rep(i , a , b)  for(lld i = a; i < b ; i++)
      #define rep1(i , a , b) for(lld i = a ; i >= b ; i--)
      #define lld long long int
      #define ulld unsigned long long int
      #define input lld* a = new lld [n]
      #define input1 lld* b = new lld [n]
      #define vec vector < lld >
      #define sz(x) x.size()
      #define pb push_back
      #define ss second
      #define ff first
      #define inf 999999999999999999
      #define fin -999999999999999999
      #define mod 1000000007
      #define umap unordered_map
      #define mpp make_pair
      #define finish(x) cout << v << " ";
      #define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

      using namespace std;

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

lld high(lld n)
{

   lld p = (lld)log2(n);
   // return (lld)pow(2, p);
   return p;
}

  void beast(){
      ulld a;cin>>a;
      ulld temp=a;
      ulld x = a;
      if(a == 1){
          cout<<"1"<<endl;return;
      }
      if(a > 1){
          while(a >= 1){
              ulld i=1;
              ulld j = high(a);

      a = a - (ulld)(pow(2,j));
      x += (ulld)pow(2,j+1)-1;
          }
          cout<< x - temp<<endl;return;
      }

  }

  signed main(){
    start();
    FAST_IO;
    lld t = 1;
    cin >> t;
    while(t--){
       beast();
    }
  }

  //  c0ded by :
  // - - - - - - - - - - - - - - - - - - - - - - beast


#include "bits/stdc++.h"
      #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      #define ld long int
      #define all(A) begin(A) , end(A)
      #define rep(i , a , b)  for(lld i = a; i < b ; i++)
      #define rep1(i , a , b) for(lld i = a ; i >= b ; i--)
      #define lld long long int
      #define ulld unsigned long long int
      #define input lld* a = new lld [n]
      #define input1 lld* b = new lld [n]
      #define vec vector < lld >
      #define sz(x) x.size()
      #define pb push_back
      #define ss second
      #define ff first
      #define inf 999999999999999999
      #define fin -999999999999999999
      #define mod 1000000007
      #define umap unordered_map
      #define mpp make_pair
      #define finish(x) cout << v << " ";
      #define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

      using namespace std;

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

lld high(lld n)
{

   lld p = (lld)log2(n);
   // return (lld)pow(2, p);
   return p;
}

  void beast(){
      lld a;cin>>a;
      lld temp=a;
      lld x = a;
      if(a == 1){
          cout<<"1"<<endl;return;
      }
      if(a > 1){
          while(a >= 1){
              lld i=1;
              lld j = high(a);

      a = a - (lld)(pow(2,j));
      x += (lld)pow(2,j+1)-1;
          }
          cout<< x - temp<<endl;return;
      }

  }

  signed main(){
    start();
    FAST_IO;
    lld t = 1;
    cin >> t;
    while(t--){
       beast();
    }
  }

  //  c0ded by :
  // - - - - - - - - - - - - - - - - - - - - - - beast


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int

//-4%3=-1
int main() {
	// your code goes here
            ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lld arr[61],power[61];
	arr[0]=0; power[0]=1LL;
	arr[1]=3; power[1]=2 ;
	for(int i=2;i<=60;i++)
	{
	    arr[i]=2*arr[i-1]+1LL;
	    power[i]=2*power[i-1];
	}
    arr[0]=1LL;
        power[0]=1LL;

    lld t;
    cin>>t;
    while(t--)
    {
        lld n;
        cin>>n;
        lld val=log2(n);
        //cout<<"VAL "<<val<<"\n";
        lld res=0;
        res+=arr[val];
        n-=power[val];
        //cout<<res<<"a\n";
        while(n!=0)
        {
            val=log2(n);
            //cout<<val<<" "<<arr[val]<<" "<<power[val]<<"c\n";
            res+=arr[val];
            n-=power[val];

        }
        cout<<res<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int

//-4%3=-1
int main() {
	// your code goes here

	lld arr[61],power[61];
	arr[0]=1, power[0]=1;
	arr[1]=3, power[1]=2 ;
	for(int i=2;i<=61;i++)
	{
	    arr[i]=2*arr[i-1]+1;
	    power[i]=2*power[i-1];
	}

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t;
    cin>>t;
    while(t--)
    {
        lld n;
        cin>>n;
        lld val=log2(n);
        lld res=0;
        res+=arr[val];
        n-=power[val];
        while(n!=0)
        {
            val=log2(n);
            res+=arr[val];
            n-=power[val];
        }
        cout<<res<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int

//-4%3=-1
int main() {
	// your code goes here
            ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lld arr[61],power[61];
	arr[0]=0; power[0]=1LL;
	arr[1]=3; power[1]=2 ;
	for(int i=2;i<=61;i++)
	{
	    arr[i]=2*arr[i-1]+1LL;
	    power[i]=2*power[i-1];
	}
    arr[0]=1LL;
        power[0]=1LL;

    lld t;
    cin>>t;
    while(t--)
    {
        lld n;
        cin>>n;
        lld val=log2l(n);
        //cout<<"VAL "<<val<<"\n";
        lld res=0;
        res+=arr[val];
        n-=power[val];
        //cout<<res<<"a\n";
        while(n!=0)
        {
            val=log2(n);
            //cout<<val<<" "<<arr[val]<<" "<<power[val]<<"c\n";
            res+=arr[val];
            n-=power[val];

        }
        cout<<res<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int

//-4%3=-1
int main() {
	// your code goes here
            ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lld arr[62],power[62];
	arr[0]=0; power[0]=1LL;
	arr[1]=3; power[1]=2 ;
	for(int i=2;i<=61;i++)
	{
	    arr[i]=2*arr[i-1]+1LL;
	    power[i]=2*power[i-1];
	}
    arr[0]=1LL;
        power[0]=1LL;

    lld t;
    cin>>t;
    while(t--)
    {
        lld n;
        cin>>n;
        lld val=log2(n);
        //cout<<"VAL "<<val<<"\n";
        lld res=0;
        res+=arr[val];
        n-=power[val];
        //cout<<res<<"a\n";
        while(n!=0)
        {
            val=log2(n);
            //cout<<val<<" "<<arr[val]<<" "<<power[val]<<"c\n";
            res+=arr[val];
            n-=power[val];

        }
        cout<<res<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int

//-4%3=-1
int main() {
	// your code goes here
            ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lld arr[61],power[61];
	arr[0]=0; power[0]=1LL;
	arr[1]=3; power[1]=2 ;
	for(int i=2;i<=61;i++)
	{
	    arr[i]=2*arr[i-1]+1LL;
	    power[i]=2*power[i-1];
	}
    arr[0]=1LL;
        power[0]=1LL;

    lld t;
    cin>>t;
    while(t--)
    {
        lld n;
        cin>>n;
        lld val=log2l(n);
        //cout<<"VAL "<<val<<"\n";
        lld res=0;
        res+=arr[val];
        n-=power[val];
        //cout<<res<<"a\n";
        while(n!=0)
        {
            val=log2l(n);
            //cout<<val<<" "<<arr[val]<<" "<<power[val]<<"c\n";
            res+=arr[val];
            n-=power[val];

        }
        cout<<res<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int

int main() {
	// your code goes here
            ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lld arr[61],power[61];
	arr[0]=0; power[0]=1LL;
	arr[1]=3; power[1]=2 ;
	for(int i=2;i<=61;i++)
	{
	    arr[i]=2*arr[i-1]+1LL;
	    power[i]=2*power[i-1];
	}
    arr[0]=1LL;
        power[0]=1LL;

    lld t;
    cin>>t;
    while(t--)
    {
        lld n;
        cin>>n;
        lld val=log2l(n);
        //cout<<"VAL "<<val<<"\n";
        lld res=0;
        res+=arr[val];
        n-=power[val];
        //cout<<res<<"a\n";
        while(n!=0)
        {
            val=log2l(n);
            //cout<<val<<" "<<arr[val]<<" "<<power[val]<<"c\n";
            res+=arr[val];
            n-=power[val];

        }
        cout<<res<<"\n";
    }
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int lt;
typedef vector<ll> vi;
typedef vector<int> vin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
#define all(a) a.begin(),a.end()
#define rep(i,a,b) for(int i=a;i<b;++i)
#define f(i,b) for(int i=0;i<b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define test(t) int t; cin>>t; while(t--) solve()
#define endl "\n"
#define p1 cout<<"YES"<<endl
#define p0 cout<<"NO"<<endl
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int mod=1e9+7;

ll mod_pow(ll a,ll n,ll mod)	//(a^n)%mod
{	ll res=1;
	while(n){	if(n&1)	res=(res*a)%mod; n/=2; a=(a*a)%mod;	}
	return res;
}

void solve();

ll cnt[60];

void init()
{
    cnt[0]=1;
    for(int i=1;i<60;++i)
    {
        cnt[i]=2ll*cnt[i-1]+1ll;
    }
}

int main()
{
    fst;
    init();
    test(t);
    // solve();
}

/**********************<="Actual code strats here"=>*****************************/

void solve()
{
    ll n;
    cin>>n;

    ll ans=0;
    while(n)
    {
        ll k=log2l(n);
        ans+=cnt[k];
        n-=(1ll<<k);
    }

    cout<<ans<<endl;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define f first
#define s second
#define ll long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define vi vector<int>
#define vvi vector<vi>
#define revloop(i,a,b) for(ll i=a;i>b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define mii map<int,int>
#define mll map<long long,long long>
#define msi map<string,int>
#define vpii vector<pair<int,int>>
#define vll  vector<long long>
#define sz(a) int(a.size())
#define last(x) x.end()
#define beg(x) x.begin()
#define all(x) begin(x),end(x)
#define FindInTree(m,n) m.find(n)!=m.end()
#define ull unsigned long long
#define inp(a,n) loop(i,0,n) cin>>a[i]
#define db1(x) cerr<<#x<<" = "<<x<<endl
#define db2(x,y) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define db3(x,y,z) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define sum(container,value) accumulate(begin(container),end(container),value)
#define tr(container,it)\
for(__typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define print(container) tr(container,it){cout<<*it<<" ";}cout<<endl
#define printarr(a,n) loop(i,0,n){ cout<<a[i]<<" "; }cout<<endl
#define ordered_set(datatype,comp) tree<datatype, null_type, comp<datatype>, rb_tree_tag, tree_order_statistics_node_update>

#pragma GCC optimise ("Ofast")

const int mod=1e9+7;
const int N=1e5+5;
const double PI=3.14159265358979311600;

ll a[N];

ll binomialCoeff(ll n, ll k)
{
    ll res = 1;
    if(n<k)
      return 0;

    if ( k > n - k )
        k = n - k;

    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

  return res;
}
void fill()
{
  ll n=ceil(log(1e19)/log(2));
  a[0]=0;
  a[1]=1;
  loop(i,2,n+1)
  {
    a[i]=2*a[i-1]+i-(i-1);
  }
}
void solve()
{
  ll n,value,ans=0;
  cin>>n;
  while(n>=1)
  {
    value=(int)log2(n)+1;
    ans=ans+a[value];
    n=n-(1ll<<(value-1));
    //cout<<n<<" "<<value<<" "<<ans<<endl;
    //cout<<a[value]<<endl;
  }
  cout<<ans<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif
  int t=1;
  cin>>t;
  fill();
  //printarr(a,5);
  while(t--)
    solve();
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define f first
#define s second
#define ll long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define vi vector<int>
#define vvi vector<vi>
#define revloop(i,a,b) for(ll i=a;i>b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define mii map<int,int>
#define mll map<long long,long long>
#define msi map<string,int>
#define vpii vector<pair<int,int>>
#define vll  vector<long long>
#define sz(a) int(a.size())
#define last(x) x.end()
#define beg(x) x.begin()
#define all(x) begin(x),end(x)
#define FindInTree(m,n) m.find(n)!=m.end()
#define ull unsigned long long
#define inp(a,n) loop(i,0,n) cin>>a[i]
#define db1(x) cerr<<#x<<" = "<<x<<endl
#define db2(x,y) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define db3(x,y,z) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define sum(container,value) accumulate(begin(container),end(container),value)
#define tr(container,it)\
for(__typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define print(container) tr(container,it){cout<<*it<<" ";}cout<<endl
#define printarr(a,n) loop(i,0,n){ cout<<a[i]<<" "; }cout<<endl
#define ordered_set(datatype,comp) tree<datatype, null_type, comp<datatype>, rb_tree_tag, tree_order_statistics_node_update>

#pragma GCC optimise ("Ofast")

const int mod=1e9+7;
const int N=1e5+5;
const double PI=3.14159265358979311600;

ll a[N];

ll binomialCoeff(ll n, ll k)
{
    ll res = 1;
    if(n<k)
      return 0;

    if ( k > n - k )
        k = n - k;

    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

  return res;
}
void fill()
{
  ll n=ceil(log(1e19)/log(2));
  a[0]=0;
  a[1]=1;
  loop(i,2,n+1)
  {
    a[i]=2*a[i-1]+i-(i-1);
  }
}
void solve()
{
  ll n,value,ans=0;
  cin>>n;
  while(n>=1)
  {
    value=floor(log2(n)+1);
    ans=ans+a[value];
    n=n-(1ll<<(value-1));
    //cout<<n<<" "<<value<<" "<<ans<<endl;
    //cout<<a[value]<<endl;
  }
  cout<<ans<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif
  int t=1;
  cin>>t;
  fill();
  //printarr(a,5);
  while(t--)
    solve();
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define f first
#define s second
#define ll long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define vi vector<int>
#define vvi vector<vi>
#define revloop(i,a,b) for(ll i=a;i>b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define mii map<int,int>
#define mll map<long long,long long>
#define msi map<string,int>
#define vpii vector<pair<int,int>>
#define vll  vector<long long>
#define sz(a) int(a.size())
#define last(x) x.end()
#define beg(x) x.begin()
#define all(x) begin(x),end(x)
#define FindInTree(m,n) m.find(n)!=m.end()
#define ull unsigned long long
#define inp(a,n) loop(i,0,n) cin>>a[i]
#define db1(x) cerr<<#x<<" = "<<x<<endl
#define db2(x,y) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define db3(x,y,z) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define sum(container,value) accumulate(begin(container),end(container),value)
#define tr(container,it)\
for(__typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define print(container) tr(container,it){cout<<*it<<" ";}cout<<endl
#define printarr(a,n) loop(i,0,n){ cout<<a[i]<<" "; }cout<<endl
#define ordered_set(datatype,comp) tree<datatype, null_type, comp<datatype>, rb_tree_tag, tree_order_statistics_node_update>

#pragma GCC optimise ("Ofast")

const int mod=1e9+7;
const int N=1e5+5;
const double PI=3.14159265358979311600;

ll a[N];

ll binomialCoeff(ll n, ll k)
{
    ll res = 1;
    if(n<k)
      return 0;

    if ( k > n - k )
        k = n - k;

    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

  return res;
}
void fill()
{
  ll n=ceil(log(1e19)/log(2));
  a[1]=0;
  loop(i,2,n+1)
  {
    a[i]=2*a[i-1]+(i-1);
  }
}
void solve()
{
  ll n,value,ans=0;
  cin>>n;
  while(n>=1)
  {
    value=(log(n)/log(2))+1;
    ans=ans+a[value]+value;
    n=n-(1ll<<(value-1));
    //cout<<n<<" "<<value<<endl;
  }
  cout<<ans<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif
  int t=1;
  cin>>t;
  fill();
  //printarr(a,5);
  while(t--)
    solve();
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define f first
#define s second
#define ll long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define vi vector<int>
#define vvi vector<vi>
#define revloop(i,a,b) for(ll i=a;i>b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define mii map<int,int>
#define mll map<long long,long long>
#define msi map<string,int>
#define vpii vector<pair<int,int>>
#define vll  vector<long long>
#define sz(a) int(a.size())
#define last(x) x.end()
#define beg(x) x.begin()
#define all(x) begin(x),end(x)
#define FindInTree(m,n) m.find(n)!=m.end()
#define ull unsigned long long
#define inp(a,n) loop(i,0,n) cin>>a[i]
#define db1(x) cerr<<#x<<" = "<<x<<endl
#define db2(x,y) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define db3(x,y,z) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define sum(container,value) accumulate(begin(container),end(container),value)
#define tr(container,it)\
for(__typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define print(container) tr(container,it){cout<<*it<<" ";}cout<<endl
#define printarr(a,n) loop(i,0,n){ cout<<a[i]<<" "; }cout<<endl
#define ordered_set(datatype,comp) tree<datatype, null_type, comp<datatype>, rb_tree_tag, tree_order_statistics_node_update>

#pragma GCC optimise ("Ofast")

const int mod=1e9+7;
const int N=1e5+5;
const double PI=3.14159265358979311600;

ll a[N];

ll binomialCoeff(ll n, ll k)
{
    ll res = 1;
    if(n<k)
      return 0;

    if ( k > n - k )
        k = n - k;

    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

  return res;
}
void fill()
{
  ll n=ceil(log(1e19)/log(2));
  a[0]=0;
  a[1]=1;
  loop(i,2,n+1)
  {
    a[i]=2*a[i-1]+i-(i-1);
  }
}
void solve()
{
  ll n,value,ans=0;
  cin>>n;
  while(n>=1)
  {
    value=((log(n)/log(2))+0.05)+1;
    ans=ans+a[value];
    n=n-(1ll<<(value-1));
    //cout<<n<<" "<<value<<" "<<ans<<endl;
    //cout<<a[value]<<endl;
  }
  cout<<ans<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif
  int t=1;
  cin>>t;
  fill();
  //printarr(a,5);
  while(t--)
    solve();
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define f first
#define s second
#define ll long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define vi vector<int>
#define vvi vector<vi>
#define revloop(i,a,b) for(ll i=a;i>b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define mii map<int,int>
#define mll map<long long,long long>
#define msi map<string,int>
#define vpii vector<pair<int,int>>
#define vll  vector<long long>
#define sz(a) int(a.size())
#define last(x) x.end()
#define beg(x) x.begin()
#define all(x) begin(x),end(x)
#define FindInTree(m,n) m.find(n)!=m.end()
#define ull unsigned long long
#define inp(a,n) loop(i,0,n) cin>>a[i]
#define db1(x) cerr<<#x<<" = "<<x<<endl
#define db2(x,y) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define db3(x,y,z) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define sum(container,value) accumulate(begin(container),end(container),value)
#define tr(container,it)\
for(__typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define print(container) tr(container,it){cout<<*it<<" ";}cout<<endl
#define printarr(a,n) loop(i,0,n){ cout<<a[i]<<" "; }cout<<endl
#define ordered_set(datatype,comp) tree<datatype, null_type, comp<datatype>, rb_tree_tag, tree_order_statistics_node_update>

#pragma GCC optimise ("Ofast")

const int mod=1e9+7;
const int N=1e5+5;
const double PI=3.14159265358979311600;

ll a[N];

ll binomialCoeff(ll n, ll k)
{
    ll res = 1;
    if(n<k)
      return 0;

    if ( k > n - k )
        k = n - k;

    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

  return res;
}

ll countDigitsAccurate(ll num,int base)
{
  ll cnt=0;
  while(num>0)
  {
    cnt++;
    num=num/base;
  }
  return cnt;
}

void fill()
{
  ll n=countDigitsAccurate(1e18+128,2);
  a[0]=0;
  a[1]=1;
  loop(i,2,n+1)
  {
    a[i]=2*a[i-1]+i-(i-1);
  }
}
void solve()
{
  ll n,value,ans=0;
  //long double arg=0.0;
  cin>>n;
  //arg=n;
  while(n>=1)
  {
    value=countDigitsAccurate(n,2);
    ans=ans+a[value];
    n=n-(1ll<<(value-1));
    //cout<<n<<" "<<value<<" "<<ans<<endl;
    //cout<<a[value]<<endl;
  }
  cout<<ans<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif
  int t=1;
  cin>>t;
  fill();
  //printarr(a,5);
  while(t--)
    solve();
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int n, k;
        cin >> n >> k;
        vector<ll> a(n);
        vector<ll> count(65, 0);
        for(int i = 0; i < n; i++)
            {
                cin >> a[i];
                int j = 0;
                while(a[i])
                {
                    count[j] += a[i]%k;
                    a[i] = a[i]/k;
                    j++;
                }
            }

            int flag = 1;
            for(int i = 0; i < count.size(); i++)
            {
                if(count[i] > 1){
                    flag = 0;
                    break;
                }
            }
        if(flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int n, k;
        cin >> n >> k;
        vector<ll> a(n);
        vector<ll> count(100, 0);
        for(int i = 0; i < n; i++)
            {
                cin >> a[i];
                int j = 0;
                while(a[i])
                {
                    count[j] += a[i]%k;
                    a[i] = a[i]/k;
                    j++;
                }
            }

            int flag = 1;
            for(int i = 0; i < count.size(); i++)
            {
                if(count[i] > 1){
                    flag = 0;
                    break;
                }
            }
        if(flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

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

        ll res = 0;

        while(n)
        {
            res = res + n;
            n = n/2;
        }

        cout << res << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll hamming(ll a, ll b)
{
    return __builtin_popcount(a^b);
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        ll res = 1;
        for(ll i = 0; i < n - 1; i++)
            res = res + hamming(i, i + 1);

        cout << res << endl;
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

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

        cout << 2*n - __builtin_popcountll(n) << endl;
    }
    return 0;
}


    #include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define inf 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    #define gcd __gcd
    using namespace std;
    int power(int x, unsigned int y, unsigned int m)
    {
        if (y == 0)
            return 1;
        int p = power(x, y/2, m) % m;
        p = (p * p) % m;

        return (y%2 == 0)? p : (x * p) % m;
    }
    int modInverse(int a, int m)
    {
        return power(a, m-2, m);
    }
    int nCrModPFermat(int n, int r, int p)
    {
           if (r==0)
              return 1;

        int fac[n+1];
        fac[0] = 1;
        for (int i=1 ; i<=n; i++)
            fac[i] = fac[i-1]*i%p;

        return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
    }
    signed main()
    {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        ll t=1;
        cin >> t;
        /*SAARE INPUTS LENA*/
        /*VARIABLES KI RANGE DEKHLENA*/
        /*EXPONENT RANGE OF OUTPUT KA DHYAN RAKHNA*/
        while(t-->0)
        {
            ll n=0;
            cin>>n;
            ll odd=ceil((double(n))/2.0);
            ll ans=0,even=0;
            ll u=log2(n);
            ll v=1;
            for (int i = 0; i < u; ++i)
            {
                v*=2;
            }
            // cout<<n<<" "<<u<<" "<<v<<" ";
            while(v!=1)
            {
                // cout<<(u+1)*(n/v-even);
                ans+=(u+1)*(n/v-even);
                even+=(n/v-even);
                v/=2;
                u--;
            }
            cout<<odd+ans<<endl;
        }
        return 0;
    }