This page is still under construction.

Parts of this page are still being built. What you see may change.

Set Definition

Time limit2sMemory limit512 MB

Summary
Find the N-th smallest number in the set generated from 1 by repeatedly applying x -> 2x+1 and x -> 3x+1.
Level

Medium6 of 10

Topics
Heap, Math, Implementation
Solved
No attempts yet

Problem

The set SS is defined by the following rules.

  1. 11 is an element of SS.
  2. If XX is an element of SS, then 2X+12X+1 and 3X+13X+1 are also elements of SS.
  3. A number that these two rules do not produce is not an element of SS.

SS is a set, so a value reachable in more than one way still counts as a single element.

List the elements of SS in increasing order and find the NN-th value.

Input

The first line contains the number of test cases TT (1≤T≤2001 \le T \le 200). Each of the next TT lines contains one integer NN (1≤N≤1071 \le N \le 10^7).

Output

For each test case, print the NN-th smallest element of SS on its own line.

Examples3

  1. Example 1

    Input
    2
    100
    254
    
    Expected output
    418
    1461
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    10
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    Expected output
    1
    3
    4
    7
    9
    10
    13
    15
    19
    21