#include <iostream>
#include <stack>
using namespace std;
int main(){
char NUM[] = {'4', '7'};
int T;
cin>>T;
for (int t = 0; t < T; t++){
int K;
stack<int> stk;
cin>>K;
K++;
while (K){
stk.push(K % 2);
K /= 2;
}
stk.pop();
while (!stk.empty()){
cout<<NUM[stk.top()];
stk.pop();
}
cout<<endl;
}
return 0;
}