Next Lucky Number

4.7

16 votes
Problem

Lucky numbers are defined as the numbers consisting only of digits 3 and 5. So, given a number N, you have to print the least lucky number strictly greater than N.

Input:
First line of input contains number of test cases T. Each test case contains a single number N.

Output:
For each test case, print the next lucky number in a separate line.

Constraints:
1<=T<=1000
1<=N<=10100

Sample Input
4
4
48
130
98

Sample Output
5
53
333
333
Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?