#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int main() {
  char word[10000];
  int hashtable[26];
  int testcase = 0;
  int i = 0;
  int count = 0;
  scanf("%d", &testcase);
  while (testcase-- > 0) {
    scanf("%s", word);
    for (i = 0; i < 26; i++)
      hashtable[i] = 0;
    count = 0;
    if (strlen(word) % 2 == 0) {
      for (i = strlen(word) / 2; i < strlen(word); i++) {
        int temp = ((int)word[i]) - 97;
        hashtable[temp]++;
      }
      for (i = 0; i < strlen(word) / 2; i++) {
        int temp = ((int)word[i]) - 97;
        hashtable[temp]--;
      }
      for (i = 0; i < 26; i++) {
        if (hashtable[i] > 0)
          count = count + hashtable[i];
      }
      printf("%d\n", count);
    } else {
      printf("%d", -1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x2794(%rbp)
movl   $0x0,-0x2798(%rbp)
movl   $0x0,-0x279c(%rbp)
lea    0xe99(%rip),%rdi
lea    -0x2794(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x2794(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2794(%rbp)
cmp    $0x0,%eax
jle    1398 <main+0x268>
lea    -0x2720(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x2798(%rbp)
cmpl   $0x1a,-0x2798(%rbp)
jge    11e1 <main+0xb1>
movslq -0x2798(%rbp),%rax
movl   $0x0,-0x2790(%rbp,%rax,4)
mov    -0x2798(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2798(%rbp)
jmp    11ae <main+0x7e>
movl   $0x0,-0x279c(%rbp)
lea    -0x2720(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1382 <main+0x252>
lea    -0x2720(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2798(%rbp)
mov    -0x2798(%rbp),%eax
mov    %eax,-0x27a8(%rbp)
lea    -0x2720(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x27a8(%rbp),%eax
cmp    %ecx,%eax
jge    128e <main+0x15e>
movslq -0x2798(%rbp),%rax
movsbl -0x2720(%rbp,%rax,1),%eax
ff
sub    $0x61,%eax
mov    %eax,-0x27a0(%rbp)
movslq -0x27a0(%rbp),%rax
mov    -0x2790(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x2790(%rbp,%rax,4)
mov    -0x2798(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2798(%rbp)
jmp    1222 <main+0xf2>
movl   $0x0,-0x2798(%rbp)
mov    -0x2798(%rbp),%eax
mov    %eax,-0x27ac(%rbp)
lea    -0x2720(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x27ac(%rbp),%eax
cmp    %ecx,%eax
jge    130c <main+0x1dc>
movslq -0x2798(%rbp),%rax
movsbl -0x2720(%rbp,%rax,1),%eax
ff
sub    $0x61,%eax
mov    %eax,-0x27a4(%rbp)
movslq -0x27a4(%rbp),%rax
mov    -0x2790(%rbp,%rax,4),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2790(%rbp,%rax,4)
mov    -0x2798(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2798(%rbp)
jmp    1298 <main+0x168>
movl   $0x0,-0x2798(%rbp)
cmpl   $0x1a,-0x2798(%rbp)
jge    136b <main+0x23b>
movslq -0x2798(%rbp),%rax
cmpl   $0x0,-0x2790(%rbp,%rax,4)
jle    1352 <main+0x222>
mov    -0x279c(%rbp),%eax
movslq -0x2798(%rbp),%rcx
add    -0x2790(%rbp,%rcx,4),%eax
mov    %eax,-0x279c(%rbp)
jmp    1357 <main+0x227>
mov    -0x2798(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2798(%rbp)
jmp    1316 <main+0x1e6>
mov    -0x279c(%rbp),%esi
lea    0xc8e(%rip),%rdi
call   1040 <printf@plt>
jmp    1393 <main+0x263>
lea    0xc77(%rip),%rdi
mov    $0xffffffff,%esi
call   1040 <printf@plt>
jmp    1175 <main+0x45>
xor    %eax,%eax
add    $0x27b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2798,%rsp
movl   $0x0,0xc(%rsp)
lea    0xeb0(%rip),%rdi
xor    %r13d,%r13d
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    136c <main+0x23c>
lea    0xe8a(%rip),%r14
lea    0x80(%rsp),%rbx
lea    0xe7e(%rip),%r15
lea    0xe71(%rip),%r12
jmp    11c0 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0xffffffff,%esi
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    136c <main+0x23c>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
pxor   %xmm0,%xmm0
movdqa %xmm0,0x10(%rsp)
movdqa %xmm0,0x20(%rsp)
movdqa %xmm0,0x30(%rsp)
movdqa %xmm0,0x40(%rsp)
movdqa %xmm0,0x50(%rsp)
movdqa %xmm0,0x60(%rsp)
movq   $0x0,0x70(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   $0x1,%al
jne    11a0 <main+0x70>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jge    1254 <main+0x124>
movslq %ebp,%rbp
nopw   0x0(%rax,%rax,1)
movsbq 0x80(%rsp,%rbp,1),%rax
addl   $0x1,-0x174(%rsp,%rax,4)
01
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1230 <main+0x100>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     129e <main+0x16e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbq 0x80(%rsp,%rbp,1),%rax
addl   $0xffffffff,-0x174(%rsp,%rax,4)
ff
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
cmp    %rax,%rbp
jl     1270 <main+0x140>
mov    0x10(%rsp),%eax
test   %eax,%eax
cmovs  %r13d,%eax
mov    0x14(%rsp),%ecx
test   %ecx,%ecx
cmovs  %r13d,%ecx
movdqu 0x18(%rsp),%xmm1
movdqu 0x28(%rsp),%xmm0
movdqa %xmm0,%xmm2
pxor   %xmm6,%xmm6
pcmpgtd %xmm6,%xmm2
pand   %xmm0,%xmm2
movdqa %xmm1,%xmm0
pcmpgtd %xmm6,%xmm0
pand   %xmm1,%xmm0
paddd  %xmm2,%xmm0
movdqu 0x48(%rsp),%xmm1
movdqu 0x68(%rsp),%xmm2
movdqu 0x38(%rsp),%xmm3
movdqu 0x58(%rsp),%xmm4
movdqa %xmm4,%xmm5
pcmpgtd %xmm6,%xmm5
pand   %xmm4,%xmm5
movdqa %xmm3,%xmm4
pcmpgtd %xmm6,%xmm4
pand   %xmm3,%xmm4
paddd  %xmm5,%xmm4
movdqa %xmm2,%xmm3
pcmpgtd %xmm6,%xmm3
pand   %xmm2,%xmm3
movdqa %xmm1,%xmm2
pcmpgtd %xmm6,%xmm2
pand   %xmm1,%xmm2
paddd  %xmm3,%xmm2
paddd  %xmm4,%xmm2
pshufd $0xee,%xmm2,%xmm1
paddd  %xmm2,%xmm1
pshufd $0x55,%xmm1,%xmm2
paddd  %xmm1,%xmm2
movd   %xmm2,%edx
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%esi
add    %edx,%esi
add    %ecx,%esi
add    %eax,%esi
mov    %r15,%rdi
jmp    11a8 <main+0x78>
xor    %eax,%eax
add    $0x2798,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i8]
%3 = alloca [26 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
br label %10
10: ; preds = %104, %0
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %105
14: ; preds = %10
%15 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 0, i32* %5
br label %17
17: ; preds = %24, %14
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 26
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [26 x i32], [26 x i32]* %3, i64 0, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %17
27: ; preds = %17
store i32 0, i32* %6
%28 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = srem i32 %29, 2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %102
32: ; preds = %27
%33 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = sdiv i32 %34, 2
store i32 %35, i32* %5
br label %36
36: ; preds = %53, %32
%37 = load i32, i32* %5
%38 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = icmp slt i32 %37, %39
br i1 %40, label %41, label %56
41: ; preds = %36
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = sub nsw i32 %46, 97
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [26 x i32], [26 x i32]* %3, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 1
store i32 %52, i32* %50
br label %53
53: ; preds = %41
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %36
56: ; preds = %36
store i32 0, i32* %5
br label %57
57: ; preds = %75, %56
%58 = load i32, i32* %5
%59 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = sdiv i32 %60, 2
%62 = icmp slt i32 %58, %61
br i1 %62, label %63, label %78
63: ; preds = %57
%64 = load i32, i32* %5
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = sub nsw i32 %68, 97
store i32 %69, i32* %8
%70 = load i32, i32* %8
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [26 x i32], [26 x i32]* %3, i64 0, i64 %71
%73 = load i32, i32* %72
%74 = add nsw i32 %73, -1
store i32 %74, i32* %72
br label %75
75: ; preds = %63
%76 = load i32, i32* %5
%77 = add nsw i32 %76, 1
store i32 %77, i32* %5
br label %57
78: ; preds = %57
store i32 0, i32* %5
br label %79
79: ; preds = %96, %78
%80 = load i32, i32* %5
%81 = icmp slt i32 %80, 26
br i1 %81, label %82, label %99
82: ; preds = %79
%83 = load i32, i32* %5
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [26 x i32], [26 x i32]* %3, i64 0, i64 %84
%86 = load i32, i32* %85
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %95
88: ; preds = %82
%89 = load i32, i32* %6
%90 = load i32, i32* %5
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [26 x i32], [26 x i32]* %3, i64 0, i64 %91
%93 = load i32, i32* %92
%94 = add nsw i32 %89, %93
store i32 %94, i32* %6
br label %95
95: ; preds = %88, %82
br label %96
96: ; preds = %95
%97 = load i32, i32* %5
%98 = add nsw i32 %97, 1
store i32 %98, i32* %5
br label %79
99: ; preds = %79
%100 = load i32, i32* %6
%101 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %100)
br label %104
102: ; preds = %27
%103 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %104
104: ; preds = %102, %99
br label %10
105: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [10000 x i8]
%2 = alloca [26 x i32]
%3 = bitcast [26 x i32]* %2 to i8*
%4 = alloca i32
%5 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%8 = load i32, i32* %4
%9 = add nsw i32 %8, -1
store i32 %9, i32* %4
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %85
11: ; preds = %0
%12 = getelementptr inbounds [26 x i32], [26 x i32]* %2, i64 0, i64 0
%13 = getelementptr inbounds [26 x i32], [26 x i32]* %2, i64 0, i64 1
%14 = getelementptr inbounds [26 x i32], [26 x i32]* %2, i64 0, i64 2
%15 = getelementptr inbounds [26 x i32], [26 x i32]* %2, i64 0, i64 10
%16 = bitcast i32* %14 to <8 x i32>*
%17 = bitcast i32* %15 to <16 x i32>*
br label %18
18: ; preds = %11, %81
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%20 = call i32 @strlen(i8* %5)
%21 = and i32 %20, 1
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %79
23: ; preds = %18
%24 = call i32 @strlen(i8* %5)
%25 = sdiv i32 %24, 2
%26 = call i32 @strlen(i8* %5)
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = sext i32 %25 to i64
br label %33
30: ; preds = %33, %23
%31 = call i32 @strlen(i8* %5)
%32 = icmp sgt i32 %31, 1
br i1 %32, label %65, label %46
33: ; preds = %28, %33
%34 = phi i64 [ %29, %28 ], [ %42, %33 ]
%35 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i64
%38 = add nsw i64 %37, -97
%39 = getelementptr inbounds [26 x i32], [26 x i32]* %2, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %39
%42 = add nsw i64 %34, 1
%43 = call i32 @strlen(i8* %5)
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %33, label %30
46: ; preds = %65, %30
%47 = load i32, i32* %12
%48 = icmp sgt i32 %47, 0
%49 = select i1 %48, i32 %47, i32 0
%50 = load i32, i32* %13
%51 = icmp sgt i32 %50, 0
%52 = select i1 %51, i32 %50, i32 0
%53 = load <8 x i32>, <8 x i32>* %16
%54 = icmp sgt <8 x i32> %53, zeroinitializer
%55 = select <8 x i1> %54, <8 x i32> %53, <8 x i32> zeroinitializer
%56 = load <16 x i32>, <16 x i32>* %17
%57 = icmp sgt <16 x i32> %56, zeroinitializer
%58 = select <16 x i1> %57, <16 x i32> %56, <16 x i32> zeroinitializer
%59 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %58)
%60 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %55)
%61 = add nuw nsw i32 %59, %60
%62 = add nuw nsw i32 %61, %52
%63 = add nuw nsw i32 %62, %49
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %63)
br label %81
65: ; preds = %30, %65
%66 = phi i64 [ %74, %65 ], [ 0, %30 ]
%67 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i64
%70 = add nsw i64 %69, -97
%71 = getelementptr inbounds [26 x i32], [26 x i32]* %2, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = add nsw i32 %72, -1
store i32 %73, i32* %71
%74 = add nuw nsw i64 %66, 1
%75 = call i32 @strlen(i8* %5)
%76 = sdiv i32 %75, 2
%77 = sext i32 %76 to i64
%78 = icmp slt i64 %74, %77
br i1 %78, label %65, label %46
79: ; preds = %18
%80 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %81
81: ; preds = %79, %46
%82 = load i32, i32* %4
%83 = add nsw i32 %82, -1
store i32 %83, i32* %4
%84 = icmp sgt i32 %82, 0
br i1 %84, label %18, label %85
85: ; preds = %81, %0
ret i32 0
}