#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
bool isPallindrome(string s) {
  long long i = 0, j = s.length() - 1;
  while (i <= j) {
    if (s[i] != s[j]) return false;
    i++;
    j--;
  }
  return true;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long i = 0, j = s.length() - 1;
    string start, mid, end;
    if (s.length() == 1) {
      cout << s << endl;
      continue;
    }
    while (i < j) {
      if (s[i] == s[j]) {
        start += s[i], end = s[j] + end;
        i++, j--;
      } else
        break;
    }
    for (long long k = i; k <= j; k++) {
      string p = s.substr(i, k - i + 1);
      if (p.length() > mid.length() and isPallindrome(p)) {
        mid = p;
      }
    }
    for (long long k = j; k >= i; k--) {
      string p = s.substr(k, j - k + 1);
      ;
      if (p.length() > mid.length() and isPallindrome(p)) {
        mid = p;
      }
    }
    cout << start << mid << end << "\n";
  }
  return 0;
}
