#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long T = 1;
  cin >> T;
  while (T--) {
    string str;
    cin >> str;
    string half;
    long long i = 0, j = str.size() - 1;
    while (i < j && str[i] == str[j]) {
      half.push_back(str[i]);
      i++;
      j--;
    }
    string mid = "";
    if (i <= j) {
      for (long long k = i; k <= j; k++) {
        long long start = k, end = k;
        while (start >= i && end <= j && str[start] == str[end]) {
          start--;
          end++;
        }
        if (start == i - 1) {
          long long newlength = (end - 1) - (start + 1) + 1;
          if (newlength > mid.size()) {
            mid = str.substr(start + 1, newlength);
          }
        } else if (end == j + 1) {
          long long newlength = (end - 1) - (start + 1) + 1;
          if (newlength > mid.size()) {
            mid = str.substr(start + 1, newlength);
          }
        }
        start = k, end = k + 1;
        if (end <= j && str[start] == str[end]) {
          while (start >= i && end <= j && str[start] == str[end]) {
            start--;
            end++;
          }
          if (start == i - 1) {
            long long newlength = (end - 1) - (start + 1) + 1;
            if (newlength > mid.size()) {
              mid = str.substr(start + 1, newlength);
            }
          } else if (end == j + 1) {
            long long newlength = (end - 1) - (start + 1) + 1;
            if (newlength > mid.size()) {
              mid = str.substr(start + 1, newlength);
            }
          }
        }
      }
    }
    cout << half << mid;
    reverse(half.begin(), half.end());
    cout << half << endl;
  }
}
