content: //{ Driver Code Starts
  // Initial Template for Java
  
  import java.io.*;
  import java.lang.*;
  import java.util.*;
  
  
  // } Driver Code Ends
  // User function Template for Java
  
  class Solution {
        public static int minChar(String s) {
         //Write your code here
          String rev = new StringBuilder(s).reverse().toString();
          String newString = s+"$"+rev;
          int len = lps(newString);
          return s.length()-len;
      }
      static int lps(String s){
          int[] lps = new int[s.length()];
          int size = s.length(), len=0, i=1;
          while(i<size){
              if(s.charAt(i)==s.charAt(len)){
                  len++;
                  lps[i]=len;
                  i++;
              }
              else{
                  if(len!=0){
                      len=lps[len-1];
                  }
                  else {
                      len=0;
                      lps[i]=0;
                      i++;
                  }
              }
          }
          return len;
      }
  }
  
  //{ Driver Code Starts.
  
  class GFG {
      public static void main(String[] args) throws IOException {
          var sc = new FastReader();
          int test = sc.nextInt();
          while (test-- > 0) {
              String s = sc.nextString();
              System.out.println(Solution.minChar(s));
  
              System.out.println("~");
          }
      }
  
      public static class FastReader {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader() {
              br = new BufferedReader(new InputStreamReader(System.in));
              st = new StringTokenizer("");
          }
  
          private void read() throws IOException {
              st = new StringTokenizer(br.readLine());
          }
  
          public String nextString() throws IOException {
              while (!st.hasMoreTokens()) read();
              return st.nextToken();
          }
  
          public int nextInt() throws IOException {
              return Integer.parseInt(nextString());
          }
  
          public long nextLong() throws IOException {
              return Long.parseLong(nextString());
          }
      }
  }
  // } Driver Code Ends