CodeForces 1388B Captain Flint and a Long Voyage

 

Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it.

In the beginning, uncle Bogdan wrote on a board a positive integer xx consisting of nn digits. After that, he wiped out xx and wrote integer kk instead, which was the concatenation of binary representations of digits xx consists of (without leading zeroes). For example, let x=729x=729, then k=111101001k=111101001 (since 7=1117=111, 2=102=10, 9=10019=1001).

After some time, uncle Bogdan understood that he doesn't know what to do with kk and asked Denis to help. Denis decided to wipe last nn digits of kk and named the new number as rr.

As a result, Denis proposed to find such integer xx of length nn that rr (as number) is maximum possible. If there are multiple valid xx then Denis is interested in the minimum one.

All crew members, including captain Flint himself, easily solved the task. All, except cabin boy Kostya, who was too drunk to think straight. But what about you?

Note: in this task, we compare integers (xx or kk) as numbers (despite what representations they are written in), so 729<1999729<1999 or 111<1000111<1000.

Input

The first line contains a single integer tt (1t10001≤t≤1000) — the number of test cases.

Next tt lines contain test cases — one per test case. The one and only line of each test case contains the single integer nn (1n1051≤n≤105) — the length of the integer xx you need to find.

It's guaranteed that the sum of nn from all test cases doesn't exceed 21052⋅105.

Output

For each test case, print the minimum integer xx of length nn such that obtained by Denis number rr is maximum possible.

Example

Input
2
1
3
Output
8
998

Note

In the second test case (with n=3n=3), if uncle Bogdan had x=998x=998 then k=100110011000k=100110011000. Denis (by wiping last n=3n=3 digits) will obtain r=100110011r=100110011.

It can be proved that the 100110011100110011 is the maximum possible rr Denis can obtain and 998998 is the minimum xx to obtain it.

9和8是唯一的二进制是四位的数,因为要最小,找出最多有几个8就行

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
#define Inf 0x3f3f3f3f
#define Maxn 20



int main() {
    int t, n, b, c;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        b = (n - 1) / 4+1;
        c = n - b;
        for (int i = 1; i <= c; i++) {
            printf("9");
        }
        for (int i = 1; i <= b; i++) {
            printf("8");
        }
        printf("\n");
    }
    return 0;

    
}

 

posted @ 2020-08-05 21:08  Vetsama  阅读(181)  评论(0)    收藏  举报