#include <bits/stdc++.h>
using namespace std;
bool isP(string &s, int l, int r) {
  for (;;) {
    if (l >= r) {
      return true;
    }
    if (s[l] != s[r]) {
      return false;
    }
    l++;
    r--;
  }
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    string s;
    cin >> s;
    int l = 0;
    int r = s.size() - 1;
    for (;;) {
      if (l >= static_cast<int>(s.size()) || r < 0 || s[l] != s[r]) {
        break;
      }
      l++;
      r--;
    }
    int pl = r;
    int pr = l;
    for (;;) {
      if (isP(s, l, pl)) {
        break;
      }
      pl--;
    }
    for (;;) {
      if (isP(s, pr, r)) {
        break;
      }
      pr++;
    }
    if (r - pr > pl - l) {
      for (int i = 0; i < l; ++i) {
        cout << s[i];
      }
      for (int i = pr; i < static_cast<int>(s.size()); ++i) {
        cout << s[i];
      }
    } else {
      for (int i = 0; i <= pl; ++i) {
        cout << s[i];
      }
      for (int i = r + 1; i < static_cast<int>(s.size()); ++i) {
        cout << s[i];
      }
    }
    cout << endl;
  }
}
