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.

bruceewayne | 193 |

manvirag982 | 182 |

Core_Ka_Bachha | 180 |

shivam123ahuja | 175 |

Sanjana Singh 1 | 173 |

mr_kksparrow | 433 |

manvirag982 | 398 |

TheHandle | 291 |

rajupraaa1234 | 276 |

Exception_404 | 268 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.