description: 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.
solution: 					/*
  					ID: abdelra29
  LANG: JAVA
  PROG: zerosum
  					*/
  						/*
  						TO LEARN
  				
  						2-euler tour
  					
  						*/
  						/*
  						TO SOLVE 
  						codeforces 722 kavi on pairing duty
  						*/
  						/*
  						bit manipulation shit
  						1-Computer Systems: A Programmer's Perspective
  						2-hacker's delight
  						*/
  						/*
  						TO WATCH
  						
  						*/
  						            import java.util.*;
  								    import java.math.*;
  								    import java.io.*; 
  								    import java.util.stream.Collectors;
  
  								       public class A{
  						            static FastScanner scan=new FastScanner();
  									     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  									     static boolean vis[][];
  		
  				public static void main(String[] args)  throws Exception 
  						      {
  						 /*
  						 very important tips 
  						 1-just fucking think backwards once in your shitty life
  						 2-consider brute forcing and finding some patterns and observations
  						 3-when you're in contest don't get out because you think there is no enough time
  						
  						 */
  						
  							//scan=new FastScanner("binary.in");
  								///out = new PrintWriter("zerosum.out");
  								 
  								 							 /*
  								 READING 
  							
  								 3-Introduction to DP with Bitmasking codefoces
  								 4-Bit Manipulation hackerearth
  								 5-read more about mobious and inculsion-exclusion 
  								 */
  								 /*
  								
  								 */
  								
  					
  								    int tt=1;
  								
  
  				tt=scan.nextInt();
  		
  //System.out.println(1^2);
  
  				int T=1;
  
  							 outer:while(tt-->0)
  								    {
  
  String s=scan.next();
  int ab=0,ba=0;
  for(int i=0;i<s.length()-1;i++)
  {
  	if(s.charAt(i)=='a'&&s.charAt(i+1)=='b')
  		ab++;
  	else if(s.charAt(i)=='b'&&s.charAt(i+1)=='a')
  		ba++;
  }
  if(ab==ba){
  	out.println(s);
  	continue outer;
  }
  String fin="";
  int yep=1000;
  for(int i=0;i<s.length();i++)
  {
  	int j=i;
  	//System.out.println(j);
  //	char c=s.charAt(i);
  	StringBuilder tmp=new StringBuilder(s);
  	if(tmp.charAt(i)=='a')
  		tmp.setCharAt(i,'b');
  	else tmp.setCharAt(i,'a');
  
  		 ab=0;
  		ba=0;
  for(int k=0;k<s.length()-1;k++)
  {
  	if(tmp.charAt(k)=='a'&&tmp.charAt(k+1)=='b')
  		ab++;
  	else if(tmp.charAt(k)=='b'&&tmp.charAt(k+1)=='a')
  		ba++;
  }
  if(ab==ba)
  {
  	out.println(tmp);
  	continue outer;
  }
  
  
  //System.out.println(i+" "+j);
  i=j;
  }
  for(int i=0;i<s.length();)
  {
  	int j=i;
  	//System.out.println(j);
  //	char c=s.charAt(i);
  	StringBuilder tmp=new StringBuilder(s);
  	int ans=0;
  	while(j<s.length()&&s.charAt(j)==s.charAt(i))
  		{
  			ans++;
  			if(tmp.charAt(j)=='a')
  				tmp.setCharAt(j,'b');
  			else tmp.setCharAt(j,'a');
  			j++;
  		}
  		//System.out.println(i);
  		//System.out.println(tmp);
  		 ab=0;
  		ba=0;
  for(int k=0;k<s.length()-1;k++)
  {
  	if(tmp.charAt(k)=='a'&&tmp.charAt(k+1)=='b')
  		ab++;
  	else if(tmp.charAt(k)=='b'&&tmp.charAt(k+1)=='a')
  		ba++;
  }
  if(ab==ba&&ans<=yep)
  {
  	yep=ans;
  	fin=tmp.toString();
  }
  //System.out.println(i+" "+j);
  i=j;
  }
  
  out.println(fin);
  
  
  								    
  
  	 }
  
  								
  
  		out.close();
  					}
  					
  			
  
  
  					static class special{
  					boolean is;
  					char c;
  					public special(boolean is,char c)
  					{
  						this.is=is;
  						this.c=c;
  					}
  
  						 @Override
  								            public int hashCode() {
  								                return (int)(c+ 31 *(is?1:0));
  								            }
  						  @Override
  								            public boolean equals(Object o){
  								            //	System.out.println("FUCK");
  								                if (o == this) return true;
  								                if (o.getClass() != getClass()) return false;
  								                special t = (special)o;
  								                return t.is == is && t.c == c;
  								            }
  					}
  		
  								   
  								     static long binexp(long a,long n)
  								    {
  								        if(n==0)
  								            return 1;
  								        long res=binexp(a,n/2);
  								        if(n%2==1)
  								            return res*res*a;
  								        else 
  								            return res*res;
  								    }
  								     
  								    static long powMod(long base, long exp, long mod) {
  								           if (base == 0 || base == 1) return base;
  								           if (exp == 0) return 1;
  								           if (exp == 1) return (base % mod+mod)%mod;
  								           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
  								           R *= R;
  								           R %= mod;
  								           if ((exp & 1) == 1) {
  								               return (base * R % mod+mod)%mod;
  								           }
  								           else return (R %mod+mod)%mod;
  								       }
  								    static double dis(double x1,double y1,double x2,double y2)
  								    {
  								        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  								    }
  								    static long mod(long x,long y)
  								        {
  								            if(x<0)
  								                x=x+(-x/y+1)*y;
  								            return x%y;
  								        }
  								     public static  long pow(long b, long e) {
  								                long r = 1;
  								                while (e > 0) {
  								                    if (e % 2 == 1) r = r * b ;
  								                    b = b * b;
  								                    e >>= 1;
  								                }
  								                return r;
  								            }
  								    private static void sort(long[] arr) {
  								            List<Long> list = new ArrayList<>();
  								            for (long object : arr) list.add(object);
  								            Collections.sort(list);
  								        //Collections.reverse(list);
  								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  								        }
  								    private static void sort2(long[] arr) {
  								            List<Long> list = new ArrayList<>();
  								            for (Long object : arr) list.add(object);
  								            Collections.sort(list);
  								        Collections.reverse(list);
  								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  								        }
  								     static class FastScanner
  						{
  						    private int BS = 1 << 16;
  						    private char NC = (char) 0;
  						    private byte[] buf = new byte[BS];
  						    private int bId = 0, size = 0;
  						    private char c = NC;
  						    private double cnt = 1;
  						    private BufferedInputStream in;
  						 
  						    public FastScanner() {
  						        in = new BufferedInputStream(System.in, BS);
  						    }
  						 
  						    public FastScanner(String s) {
  						        try {
  						            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
  						        } catch (Exception e) {
  						            in = new BufferedInputStream(System.in, BS);
  						        }
  						    }
  						 
  						    private char getChar() {
  						        while (bId == size) {
  						            try {
  						                size = in.read(buf);
  						            } catch (Exception e) {
  						                return NC;
  						            }
  						            if (size == -1) return NC;
  						            bId = 0;
  						        }
  						        return (char) buf[bId++];
  						    }
  						 
  						    public int nextInt() {
  						        return (int) nextLong();
  						    }
  						 
  						    public int[] nextInts(int N) {
  						        int[] res = new int[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = (int) nextLong();
  						        }
  						        return res;
  						    }
  						 
  						    public long[] nextLongs(int N) {
  						        long[] res = new long[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = nextLong();
  						        }
  						        return res;
  						    }
  						 
  						    public long nextLong() {
  						        cnt = 1;
  						        boolean neg = false;
  						        if (c == NC) c = getChar();
  						        for (; (c < '0' || c > '9'); c = getChar()) {
  						            if (c == '-') neg = true;
  						        }
  						        long res = 0;
  						        for (; c >= '0' && c <= '9'; c = getChar()) {
  						            res = (res << 3) + (res << 1) + c - '0';
  						            cnt *= 10;
  						        }
  						        return neg ? -res : res;
  						    }
  						 
  						    public double nextDouble() {
  						        double cur = nextLong();
  						        return c != '.' ? cur : cur + nextLong() / cnt;
  						    }
  						 
  						    public double[] nextDoubles(int N) {
  						        double[] res = new double[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = nextDouble();
  						        }
  						        return res;
  						    }
  						 
  						    public String next() {
  						        StringBuilder res = new StringBuilder();
  						        while (c <= 32) c = getChar();
  						        while (c > 32) {
  						            res.append(c);
  						            c = getChar();
  						        }
  						        return res.toString();
  						    }
  						 
  						    public String nextLine() {
  						        StringBuilder res = new StringBuilder();
  						        while (c <= 32) c = getChar();
  						        while (c != '\n') {
  						            res.append(c);
  						            c = getChar();
  						        }
  						        return res.toString();
  						    }
  						 
  						    public boolean hasNext() {
  						        if (c > 32) return true;
  						        while (true) {
  						            c = getChar();
  						            if (c == NC) return false;
  						            else if (c > 32) return true;
  						        }
  						    }
  						}
  
  								     static class Pair implements Comparable<Pair>{
  								            public long x, y,z;
  								            public Pair(long x1, long y1,long z1) {
  								                x=x1;
  								                y=y1;
  								                z=z1;
  								            }
  								             public Pair(long x1, long y1) {
  								                x=x1;
  								                y=y1;
  								    
  								            }
  								            
  								            @Override
  								            public int hashCode() {
  								                return (int)(x + 31 * y);
  								            }
  								            public String toString() {
  								                return x + " " + y+" "+z;
  								            }
  								            @Override
  								            public boolean equals(Object o){
  								                if (o == this) return true;
  								                if (o.getClass() != getClass()) return false;
  								                Pair t = (Pair)o;
  								                return t.x == x && t.y == y&&t.z==z;
  								            }
  								    public int compareTo(Pair o)
  								    {
  								  	
  								return (int)(x-o.x);
  								     
  								        }
  								     
  								    }
  								}
  								
  								    
  								   
  
  								     
  