You are given a string s of length n consisting of characters a and/or b.

Let \operatorname{AB}(s) be the number of occurrences of string ab in s as a substring. Analogically, \operatorname{BA}(s) is the number of occurrences of ba in s as a substring.

In one step, you can choose any index i and replace s_i with character a or b.

What is the minimum number of steps you need to make to achieve \operatorname{AB}(s) = \operatorname{BA}(s)?

Reminder:

The number of occurrences of string d in s as substring is the number of indices i (1 ≤ i ≤ |s| - |d| + 1) such that substring s_i s_{i + 1} ... s_{i + |d| - 1} is equal to d. For example, \operatorname{AB}(aabbbabaa) = 2 since there are two indices i: i = 2 where aabbbabaa and i = 6 where aabbbabaa.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.

The first and only line of each test case contains a single string s (1 ≤ |s| ≤ 100, where |s| is the length of the string s), consisting only of characters a and/or b.

Output

For each test case, print the resulting string s with \operatorname{AB}(s) = \operatorname{BA}(s) you'll get making the minimum number of steps.

If there are multiple answers, print any of them.

Example

Input


4
b
aabbbabaa
abbb
abbaab


Output


b
aabbbabaa
bbbb
abbaaa

Note

In the first test case, both \operatorname{AB}(s) = 0 and \operatorname{BA}(s) = 0 (there are no occurrences of ab (ba) in b), so can leave s untouched.

In the second test case, \operatorname{AB}(s) = 2 and \operatorname{BA}(s) = 2, so you can leave s untouched. 

In the third test case, \operatorname{AB}(s) = 1 and \operatorname{BA}(s) = 0. For example, we can change s_1 to b and make both values zero.

In the fourth test case, \operatorname{AB}(s) = 2 and \operatorname{BA}(s) = 1. For example, we can change s_6 to a and make both values equal to 1.
1
abbabababbabababbababbbabbbbabbbabaabaabba
 4
b
aabbbabaa
abbb
abbaab
 1
aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbab

abbabababbabababbababbbabbbbabbbabaabaabba
 b
aabbbabaa
bbbb
bbbaab
 baaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbab

 //package eround101;

import java.util.*;
import java.io.*;
import java.lang.*;
import java.util.StringTokenizer;

public class Solution {

    static HritikScanner sc = new HritikScanner();
    static PrintWriter pw = new PrintWriter(System.out, true);
    final static int MOD = 1000000007;
    static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) {

        int t = ni();
        while (t-- > 0) {
            solve();
        }
    }

    static void solve() {
        char[] arr = sc.next().toCharArray();
        int ab = 0;
        int ba = 0;
        int n = arr.length;
        for(int i = 0; i < n-1; i++)
        {
            if(arr[i] == 'a' && arr[i+1] == 'b')
                ab++;
            if(arr[i] == 'b' && arr[i+1] == 'a')
                ba++;
        }
        int diff = 0;
        if(ab > ba)
        {
            arr[0] = 'b';
        }
        else if(ab < ba)
        {
            arr[0] = 'a';
        }
        for(char ele : arr)
        {
            System.out.print(ele);
        }
        pl();
    }
        /////////////////////////////////////////////////////////////////////////////////
    static class FenwickTree { // Binary Index Tree
        int[] tree;
        static int size;

        public FenwickTree(int size) {
            this.size = size;
            tree = new int[size + 5];
        }

        public void add(int i, int val) {
            while (i <= size) {
                tree[i] += val;
                i += i & -i;  // adding the decimal value of the last set bit.
            }
        }

        public int sum(int i) {
            int res = 0;
            while (i >= 1) {
                res += tree[i];
                i -= i & -i; // deleting the last set bit
            }
            return res;
        }

        public int sum(int l, int r) {
            return sum(r) - sum(l - 1);
        }
    }

    /////////////////////////////////////////////////////////////////////////////////
    static int[] nextIntArray(int n) {
        int[] arr = new int[n];
        int i = 0;
        while (i < n) {
            arr[i++] = ni();
        }
        return arr;
    }

    static long[] nextLongArray(int n) {
        long[] arr = new long[n];
        int i = 0;
        while (i < n) {
            arr[i++] = nl();
        }
        return arr;
    }

    static int[] nextIntArray1(int n) {
        int[] arr = new int[n + 1];
        int i = 1;
        while (i <= n) {
            arr[i++] = ni();
        }
        return arr;
    }

    /////////////////////////////////////////////////////////////////////////////////
    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static double nd() {
        return sc.nextDouble();
    }

    /////////////////////////////////////////////////////////////////////////////////
    static void pl() {
        pw.println();
    }

    static void p(Object o) {
        pw.print(o + " ");
    }

    static void pl(Object o) {
        pw.println(o);
    }

    static void psb(StringBuilder sb) {
        pw.print(sb);
    }

    static void pa(Object arr[]) {
        for (Object o : arr) {
            p(o);
        }
        pl();
    }

    static void pa(int arr[]) {
        for (int o : arr) {
            p(o);
        }
        pl();
    }

    static void pa(long arr[]) {
        for (long o : arr) {
            p(o);
        }
        pl();
    }

    static void pa(double arr[]) {
        for (double o : arr) {
            p(o);
        }
        pl();
    }

    static void pa(char arr[]) {
        for (char o : arr) {
            p(o);
        }
        pl();
    }

    static void pa(List list) {
        for (Object o : list) {
            p(o);
        }
        pl();
    }

    static void pa(Object[][] arr) {

        for (int i = 0; i < arr.length; ++i) {
            for (Object o : arr[i]) {
                p(o);
            }
            pl();
        }
    }

    static void pa(int[][] arr) {
        for (int i = 0; i < arr.length; ++i) {
            for (int o : arr[i]) {
                p(o);
            }
            pl();
        }
    }

    static void pa(long[][] arr) {
        for (int i = 0; i < arr.length; ++i) {
            for (long o : arr[i]) {
                p(o);
            }
            pl();
        }
    }

    static void pa(char[][] arr) {
        for (int i = 0; i < arr.length; ++i) {
            for (char o : arr[i]) {
                p(o);
            }
            pl();
        }
    }

    static void pa(double[][] arr) {
        for (int i = 0; i < arr.length; ++i) {
            for (double o : arr[i]) {
                p(o);
            }
            pl();
        }
    }

/////////////////////////////////////////////////////////////////////////////////
    static void print(Object s) {
        System.out.println(s);
    }

    /////////////////////////////////////////////////////////////////////////////////
    //-----------HritikScanner class for faster input----------//
    static class HritikScanner {

        BufferedReader br;
        StringTokenizer st;

        public HritikScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    //////////////////////////////////////////////////////////////////
    public static class Pair implements Comparable<Pair> {

        int num, row, col;

        Pair(int num, int row, int col) {
            this.num = num;
            this.row = row;
            this.col = col;
        }

        public int get1() {
            return num;
        }

        public int get2() {
            return row;
        }

        public int compareTo(Pair A) {
            return this.num - A.num;
        }

        public String toString() {
            return num + " " + row + " " + col;
        }
    }

    //////////////////////////////////////////////////////////////////
    // Function to return gcd of a and b time complexity O(log(a+b))
    static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    // method to return LCM of two numbers 
    static long lcm(int a, int b) {
        return (a / gcd(a, b)) * b;
    }

    //////////////////////////////////////////////////////////////////
    static boolean isPrime(long n) {
        // Corner cases 
        if (n <= 1) {
            return false;
        }
        if (n <= 3) {
            return true;
        }

        // This is checked so that we can skip  
        // middle five numbers in below loop 
        if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }

        for (long i = 5; i * i <= n; i = i + 6) {
            if (n % i == 0 || n % (i + 2) == 0) {
                return false;
            }
        }

        return true;
    }
    //////////////////////////////////////////////////////////////////

    static boolean isPowerOfTwo(long n) {
        if (n == 0) {
            return false;
        }

        return (long) (Math.ceil((Math.log(n) / Math.log(2))))
                == (long) (Math.floor(((Math.log(n) / Math.log(2)))));
    }

    public static long getFact(int n) {
        long ans = 1;
        while (n > 0) {
            ans *= n;
            ans %= MOD;
            n--;
        }
        return ans;
    }

    public static long pow(long n, int pow) {
        if (pow == 0) {
            return 1;
        }
        long temp = pow(n, pow / 2) % MOD;
        temp *= temp;
        temp %= MOD;
        if (pow % 2 == 1) {
            temp *= n;
        }
        temp %= MOD;
        return temp;

    }

    public static long nCr(int n, int r) {
        long ans = 1;
        int temp = n - r;
        while (n > temp) {
            ans *= n;
            ans %= MOD;
            n--;
        }
        ans *= pow(getFact(r) % MOD, MOD - 2) % MOD;
        ans %= MOD;
        return ans;
    }

    //////////////////////////////////////////////////////////////////
    // method returns Nth power of A 
    static double nthRoot(int A, int N) {

        // intially guessing a random number between 
        // 0 and 9 
        double xPre = Math.random() % 10;

        // smaller eps, denotes more accuracy 
        double eps = 0.001;

        // initializing difference between two 
        // roots by INT_MAX 
        double delX = 2147483647;

        // xK denotes current value of x 
        double xK = 0.0;

        // loop untill we reach desired accuracy 
        while (delX > eps) {
            // calculating current value from previous 
            // value by newton's method 
            xK = ((N - 1.0) * xPre
                    + (double) A / Math.pow(xPre, N - 1)) / (double) N;
            delX = Math.abs(xK - xPre);
            xPre = xK;
        }

        return xK;
    }

}
