#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, i, j, k, f, x, y, z, ans;
  long long t;
  cin >> t;
  while (t--) {
    m = 0, i = 0, j = 0, f = 0, x = 0, y = 0, z = 0, ans = 0;
    string s;
    cin >> s;
    if (s[0] != s[s.size() - 1]) s[0] = s[s.size() - 1];
    cout << s << "\n";
  }
  return 0;
}
