#include
#include
#include <math.h>
using namespace std;
int main () {
int n;
long long a;
double sum = 0;
cin >> n;
while(n–){
cin >> a;
string temp = to_string(a);
int counter = 0;
while(counter < temp.length()){
if(temp.at(counter) == ‘1’){
sum = sum + pow(2,counter);
}
counter++;
}
cout << sum << endl;
sum = 0;
}
}