import java.util.*;

public class test{
	
    public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
    	int t = scanner.nextInt();
    	for(int i=0;i<t;i++){
    		long n = scanner.nextInt();//我写的int错了,囧
    		int weishu = 1;
    		long temp = 0;
    		while(temp<n){
    			temp += Math.pow(2, weishu);
    			weishu++;
    		}
    		weishu--;
    		temp -= Math.pow(2, weishu);
    		long temp2 = n-temp-1;
    		//System.out.println(weishu);
    		//System.out.println(temp2);
    		String s = "";
    		int weishu2 = 0;
    		while(temp2!=0){
    			if(temp2%2==0){
    				s = "4"+s;
    				weishu2++;
    			}
    			else{
    				s = "7"+s;
    				weishu2++;
    			}
    			temp2 /= 2;
    		}
    		while(weishu2<weishu){
    			s = "4"+s;
    			weishu2++;
    		}
    		System.out.println(s);
    	}
    }
}

没过,可能是输入我写的int,输入写成long估计能过,555555