#include <iostream>
using namespace std;

using LL = long long;

void solve(){
    int k;
    cin>>k;

    auto cal=[](LL n){
        LL a = (n>=5)+(n-5)/10;
        LL b = (n>=3)+(n-3)/6;
        LL c = (n>=15)+(n-15)/30;
        return a+b-c;
    };

    LL l=0,r=1e12;
    LL ans=-1;
    while(l<=r){
        LL mid=(l+r)/2;
        if(cal(mid)<k){
            ans=mid+1;
            l=mid+1;
        }else{
            r=mid-1;
        }
    }

    cout<<ans<<"\n";
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    cin>>t;
    while(t--)solve();
}
// 64 位输出请用 printf("%lld")