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.

d_Coder00 | 134 |

Astikeysingh | 128 |

dungeon_master1299 | 126 |

rajendrashekhawat063 | 115 |

VivSisMMM | 112 |

Pulkit__Sharma__ | 646 |

Anirban166 | 531 |

abducodes | 508 |

Found_me | 474 |

Sathvik Avasarala | 418 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.