#include <bits/stdc++.h>
#define endl "\n"
#define INT long long int

using namespace std;

char infile[100], outfile[100];

int main() {
    ios::sync_with_stdio(false);
    INT T,a, b, n, t, i, I,c,d;
    cin >> T;
    for(I=1;I<=T;I++){
        sprintf(infile, ".%d.in", I);
        freopen(infile, "w", stdout);
        scanf("%lld",&n);
        printf("%lld\n", n);
        sprintf(outfile, ".%d.out", I);
        freopen(outfile, "w", stdout);
        for(i=0;i<n-((n+3)/4);i++) printf("9");
        for(i=0;i<(n+3)/4;i++) printf("8");
        printf("\n");
    }
}
