#include <bits/stdc++.h>
using namespace std;
string s;
bool palindrom(int a, int b) {
  int sr = (b - a) / 2;
  for (int i = 0; i <= sr; i++)
    if (s[a + i] != s[b - i]) return false;
  return true;
}
pair<int, int> maxpalindrom(int a, int b) {
  pair<int, int> p1, p2;
  for (int i = b; true; i--) {
    if (palindrom(a, i)) {
      p1.first = a;
      p1.second = i;
      break;
    }
  }
  for (int i = a; true; i++) {
    if (palindrom(i, b)) {
      p2.first = i;
      p2.second = b;
      break;
    }
  }
  if (p1.second - p1.first > p2.second - p2.first) return p1;
  return p2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pair<int, int> par;
  int t, n, k;
  cin >> t;
  while (t--) {
    s = "";
    cin >> s;
    n = s.size() / 2;
    for (k = 0; true; k++) {
      if (k == n || s[k] != s[s.size() - k - 1]) {
        par = maxpalindrom(k, s.size() - k - 1);
        for (int i = 0; i < k; i++) cout << s[i];
        for (int i = par.first; i <= par.second; i++) cout << s[i];
        for (int i = k - 1; i >= 0; i--) cout << s[i];
        break;
      }
    }
    cout << endl;
  }
}
