import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {

    // Complete the anagram function below.
    static int anagram(String s) {
        char[] c = s.toCharArray();
        ArrayList<Character> hs = new ArrayList<Character>();
        if(c.length%2==1) return -1;
        for(int i=0;i<c.length/2;i++){
            hs.add(c[i]);
            System.out.println(c[i]);
        }
        int count = hs.size();
        for(int i=0;i<count;i++){
            System.out.println(c[c.length-1-i]);
            System.out.println(hs.contains(c[c.length-1-i]));
            hs.remove(c[c.length-1-i]);
            try{
                if(hs.size()!=0 && hs.contains(c[c.length-1-i]) ) hs.remove(c[c.length-1-i]);
            }
            catch(Exception e){ 
                continue;
                              
            }
        }
        if(hs.size()==0) return -1;
        else return hs.size();
    }

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        int q = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        for (int qItr = 0; qItr < q; qItr++) {
            String s = scanner.nextLine();

            int result = anagram(s);
            System.out.println("");
            bufferedWriter.write(String.valueOf(result));
            bufferedWriter.newLine();
        }

        bufferedWriter.close();

        scanner.close();
    }
}

@@ -182,52 +182,8 @@
  %7B%0A%0A
-    // Complete the anagram function below.%0A
     
@@ -257,21 +257,16 @@
         
-Array
 List%3CCha
@@ -468,326 +468,220 @@
     
-int count = hs.size();%0A        for(int i=0;i%3Ccount;i++)%7B%0A            System.out.println(c%5Bc.length-1-i%5D);%0A            System.out.println(hs.contains(c%5Bc.length-1-i%5D));%0A            hs.remove(c%5Bc.length-1-i%5D);%0A            try%7B%0A                if(hs.size()!=0 && hs.contains(c%5Bc.length-1-i%5D) ) hs.remove(c%5Bc.length-1-i%5D);
+ListIterator%3CCharacter%3E it = hs.listIterator();%0A        int count = 0;%0A        while(it.hasNext())%7B%0A            char ch = it.next();%0A            for(int i=c.length/2;i%3Cc.length;i++)%7B%0A                if(ch==c%5Bi%5D)%7B
 %0A   
@@ -678,37 +678,32 @@
 c%5Bi%5D)%7B%0A         
-   %7D%0A
             catc
@@ -701,30 +701,22 @@
     
- catch(Exception e)%7B %0A
+c%5Bi%5D='5';%0A    
     
@@ -733,14 +733,13 @@
   co
+u
 nt
-inue
+++
 ;%0A  
@@ -747,32 +747,40 @@
                 
+ break;%0A
            %0A    
@@ -774,16 +774,22 @@
         
+     %7D
 %0A       
@@ -816,16 +816,23 @@
      if(
+count==
 hs.size(
@@ -836,11 +836,8 @@
 ze()
-==0
 ) re
@@ -833,34 +833,33 @@
 .size()) return 
--1
+0
 ;%0A        else r
@@ -873,16 +873,22 @@
 s.size()
+-count
 ;%0A    %7D%0A

add Anagram.java