A number is called faithful if you can write it as the sum of distinct powers of 7.

**e.g., ** 2457 = 7 + 7^{2} + 7^{4 . }If we order all the faithful numbers, we get the sequence 1 = 7^{0}, 7 = 7^{1}, 8 = 7^{0} + 7^{1}, 49 = 7^{2}, 50 = 7^{0} + 7^{2} . . . and so on.

Given some value of **N**, you have to find the **N'th** faithful number.

**Input: **

The first line of input contains a single integer **T** denoting the number of test cases. Then **T** test cases follow. Each test case consists of one line. The line consists of a positive integer **N**.

**Output:**

Corresponding to each test case, in a new line, print the value of the Nth faithful number.

**Constraints:**

1 ≤ T ≤ 100

1 ≤ N ≤ 10^{6 }

**Example:**

**Input:**

3

3

7

100

**Output:**

8

57

134505

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

cs_abhi | 102 |

PiyushPandey4 | 100 |

codefundo | 95 |

kya_bolti_public | 93 |

masterishaan19 | 74 |

PiyushPandey4 | 916 |

john_wick | 765 |

ASWATHAMA | 565 |

UsfShilpa | 556 |

akhyasharma01 | 547 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.