#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int NINF = -INF - 1;
const int maxn = 1e6 + 10;
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string ss;
    cin >> ss;
    string tmp = ss;
    int len = ss.length();
    reverse(tmp.begin(), tmp.end());
    if (ss == tmp) {
      cout << ss << endl;
      continue;
    }
    int l = 0, r = len - 1;
    while (l < r) {
      if (ss[l] == ss[r])
        l++, r--;
      else
        break;
    }
    string prefix = ss.substr(0, l);
    string suffix = ss.substr(r + 1, len - r - 1);
    string midpre, midsuf;
    for (int i = l; i <= r; ++i) {
      string t = ss.substr(l, i - l + 1);
      string rt = t;
      reverse(rt.begin(), rt.end());
      if (rt == t) {
        midpre = t;
      }
    }
    for (int i = r; i >= l; --i) {
      string t = ss.substr(i, r - i + 1);
      string rt = t;
      reverse(rt.begin(), rt.end());
      if (rt == t) {
        midsuf = t;
      }
    }
    if (midpre.length() >= midsuf.length()) {
      cout << prefix + midpre + suffix << endl;
    } else
      cout << prefix + midsuf + suffix << endl;
  }
  return 0;
}
