#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    int i = 0;
    int n = str.length();
    if (n == 1) {
      cout << str << "\n";
      continue;
    }
    int j = n - 1;
    int s = -1;
    int f = n;
    while (i <= j && str[i] == str[j]) {
      s = i;
      f = j;
      i++;
      j--;
    }
    if (i >= j) {
      cout << str << "\n";
      continue;
    }
    int a = 1;
    for (int i = 1; i < f - s - 1; i++) {
      int p = s + 1;
      int q = s + i + 1;
      bool flag = 1;
      while (p <= q) {
        if (str[p] != str[q]) {
          flag = 0;
          break;
        }
        p++;
        q--;
      }
      if (flag) {
        a = i + 1;
      }
    }
    int b = 1;
    for (int i = 1; i < f - s - 1; i++) {
      int p = f - 1 - i;
      int q = f - 1;
      bool flag = 1;
      while (p <= q) {
        if (str[p] != str[q]) {
          flag = 0;
          break;
        }
        p++;
        q--;
      }
      if (flag) {
        b = i + 1;
      }
    }
    if (a >= b) {
      cout << str.substr(0, s + a + 1) << str.substr(f, n - f) << "\n";
    } else {
      cout << str.substr(0, s + 1) << str.substr(f - b, n - f + b) << "\n";
    }
  }
}
