#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
bool ok(string s) {
  int l = 0, r = (int)s.size() - 1;
  while (l < r) {
    if (s[l] != s[r]) return false;
    ++l, --r;
  }
  return true;
}
void solve() {
  string s;
  cin >> s;
  int n = (int)s.size();
  int i = 0, j = n - 1;
  string t = "", second = "";
  while (i < j && s[i] == s[j]) {
    t += s[i];
    ++i, --j;
  }
  string best = "", curr = "";
  for (int k = i; k <= j; ++k) {
    curr += s[k];
    if (ok(curr) && (int)curr.size() > (int)best.size()) best = curr;
  }
  curr = "";
  for (int k = j; k >= i; --k) {
    curr += s[k];
    if (ok(curr) && (int)curr.size() > (int)best.size()) best = curr;
  }
  second = t;
  reverse(second.begin(), second.end());
  cout << t + best + second << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
