#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int n;
    cin >> n;
    int gnum;
    while (1) {
      gnum = n;
      while (gnum > 0) {
        if (gnum % 3 == 2) {
          break;
        }
        gnum = gnum / 3;
      }
      if (gnum == 1 || gnum == 0) {
        break;
      }
      n++;
    }
    cout << n << endl;
  }
  return 0;
}
