#include <bits/stdc++.h>
using namespace std;
vector<long long> c;
vector<string> s, r;
string f;
bool isPalindrome(string s) {
  string temp = s;
  reverse(temp.begin(), temp.end());
  if (s == temp) return true;
  return false;
}
string prefix(string s) {
  string res = "";
  for (int i = 1; i <= s.length(); i++) {
    if (isPalindrome(s.substr(0, i))) {
      if (res.length() < s.substr(0, i).length()) {
        res = s.substr(0, i);
      }
    }
  }
  return res;
}
string suffix(string s) {
  reverse(s.begin(), s.end());
  string res = "";
  for (int i = 1; i <= s.length(); i++) {
    if (isPalindrome(s.substr(0, i))) {
      if (res.length() < s.substr(0, i).length()) {
        res = s.substr(0, i);
      }
    }
  }
  reverse(res.begin(), res.end());
  return res;
}
int32_t main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    if (s.length() == 0) {
      cout << '\n';
      continue;
    }
    string a;
    int i = 0, j = s.length() - 1;
    while (i < j) {
      if (s[i] == s[j]) {
        a += s[i];
        i++;
        j--;
      } else
        break;
    }
    string temp = a;
    reverse(temp.begin(), temp.end());
    string pre = prefix(s.substr(i, j - i + 1));
    string suff = suffix(s.substr(i, j - i + 1));
    if (pre.length() > suff.length()) {
      cout << a + pre + temp << endl;
    } else
      cout << a + suff + temp << endl;
  }
  return 0;
}
