#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int ans[1000];
  int cur = 1;
  for (int i = 0; i < 1000; i++) {
    while (cur % 3 == 0 || cur % 10 == 3) cur++;
    ans[i] = cur;
    cur++;
  }
  for (int i = 0; i < t; i++) {
    int tmp;
    cin >> tmp;
    cout << ans[tmp - 1] << endl;
  }
}
