#include <bits/stdc++.h>
using namespace std;
bool isPalin(string s, int st, int e) {
  while (st < e) {
    if (s[st] == s[e]) {
      st++;
      e--;
    } else
      return false;
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    string ans = "";
    int start = 0, end = n - 1, same = 0;
    while (start < end) {
      if (s[start] == s[end]) {
        ans += s[start];
        start++;
        end--;
      } else
        break;
    }
    string finAns = ans;
    reverse(ans.begin(), ans.end());
    string ans1 = "", ans2 = "";
    for (int i = start; i <= end; i++) {
      if (isPalin(s, start, i)) ans1 = s.substr(start, i - start + 1);
    }
    for (int i = end; i >= start; i--) {
      if (isPalin(s, i, end)) ans2 = s.substr(i, end - i + 1);
    }
    if (ans1.size() > ans2.size()) {
      finAns += (ans1 + ans);
    } else
      finAns += (ans2 + ans);
    cout << finAns << endl;
  }
}
