#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 /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int main() {
  int t, count = 0, i, j, k, l;
  char a[10000];
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%s", a);
    l = strlen(a);
    if (l % 2 == 1) {
      printf("-1\n");
    } else {
      for (j = 0; j < l / 2; j++) {
        for (k = l / 2; k <= l; k++) {
          if (a[j] == a[k]) {
            a[k] = 1;
            count++;
            break;
          }
        }
      }
      printf("%d\n", l / 2 - count);
      count = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1296 <main+0x166>
lea    -0x2730(%rbp),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x2730(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11b9 <main+0x89>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1283 <main+0x153>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2734(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2734(%rbp),%eax
cmp    %ecx,%eax
jge    125e <main+0x12e>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     124b <main+0x11b>
movslq -0x14(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%eax
ff
movslq -0x18(%rbp),%rcx
movsbl -0x2730(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    1238 <main+0x108>
movslq -0x18(%rbp),%rax
movb   $0x1,-0x2730(%rbp,%rax,1)
01
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    124b <main+0x11b>
jmp    123d <main+0x10d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f2 <main+0xc2>
jmp    1250 <main+0x120>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <main+0x90>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
sub    -0xc(%rbp),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1288 <main+0x158>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1162 <main+0x32>
xor    %eax,%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2728,%rsp
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    124f <main+0x10f>
lea    0xe8d(%rip),%r14
lea    0x10(%rsp),%r13
lea    0xe84(%rip),%r12
xor    %r15d,%r15d
jmp    11ac <main+0x6c>
nopw   0x0(%rax,%rax,1)
sub    %r8d,%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
jge    124f <main+0x10f>
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
mov    %esi,%ecx
and    $0xfffffffe,%ecx
mov    %eax,%edx
sub    %ecx,%edx
cmp    $0x1,%edx
jne    11f0 <main+0xb0>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
jmp    119d <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
sar    %esi
xor    %r8d,%r8d
cmp    $0x2,%eax
jl     1190 <main+0x50>
movslq %esi,%rcx
mov    %ecx,%r9d
lea    (%rsp,%rcx,1),%rdx
add    $0x10,%rdx
mov    %eax,%edi
sub    %ecx,%edi
add    $0x1,%edi
xor    %ebp,%ebp
xor    %r8d,%r8d
jmp    1235 <main+0xf5>
cs nopw 0x0(%rax,%rax,1)
movb   $0x1,(%rdx,%rcx,1)
add    $0x1,%r8d
add    $0x1,%rbp
cmp    %r9,%rbp
je     1190 <main+0x50>
cmp    %eax,%esi
jg     1228 <main+0xe8>
mov    0x10(%rsp,%rbp,1),%bl
xor    %ecx,%ecx
nop
cmp    (%rdx,%rcx,1),%bl
je     1220 <main+0xe0>
add    $0x1,%rcx
cmp    %ecx,%edi
jne    1240 <main+0x100>
jmp    1228 <main+0xe8>
xor    %eax,%eax
add    $0x2728,%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"-1\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10000 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %4
br label %10
10: ; preds = %70, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %73
14: ; preds = %10
%15 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, 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)
%17 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = srem i32 %19, 2
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %69
24: ; preds = %14
store i32 0, i32* %5
br label %25
25: ; preds = %60, %24
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = sdiv i32 %27, 2
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %63
30: ; preds = %25
%31 = load i32, i32* %7
%32 = sdiv i32 %31, 2
store i32 %32, i32* %6
br label %33
33: ; preds = %56, %30
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %59
37: ; preds = %33
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %42, %47
br i1 %48, label %49, label %55
49: ; preds = %37
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 %51
store i8 1, i8* %52
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %59
55: ; preds = %37
br label %56
56: ; preds = %55
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %33
59: ; preds = %49, %33
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %25
63: ; preds = %25
%64 = load i32, i32* %7
%65 = sdiv i32 %64, 2
%66 = load i32, i32* %3
%67 = sub nsw i32 %65, %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %63, %22
br label %70
70: ; preds = %69
%71 = load i32, i32* %4
%72 = add nsw i32 %71, 1
store i32 %72, i32* %4
br label %10
73: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [3 x i8] c"-1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %54
8: ; preds = %0, %50
%9 = phi i32 [ %51, %50 ], [ 0, %0 ]
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = call i32 @strlen(i8* %4)
%12 = srem i32 %11, 2
%13 = sdiv i32 %11, 2
%14 = icmp eq i32 %12, 1
br i1 %14, label %22, label %15
15: ; preds = %8
%16 = icmp sgt i32 %11, 1
br i1 %16, label %17, label %46
17: ; preds = %15
%18 = icmp sgt i32 %13, %11
%19 = sext i32 %13 to i64
%20 = add nuw i32 %11, 1
%21 = zext i32 %13 to i64
br label %24
22: ; preds = %8
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %50
24: ; preds = %17, %42
%25 = phi i64 [ 0, %17 ], [ %44, %42 ]
%26 = phi i32 [ 0, %17 ], [ %43, %42 ]
br i1 %18, label %42, label %27
27: ; preds = %24
%28 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %25
%29 = load i8, i8* %28
br label %34
30: ; preds = %34
%31 = add nsw i64 %35, 1
%32 = trunc i64 %31 to i32
%33 = icmp eq i32 %20, %32
br i1 %33, label %42, label %34
34: ; preds = %27, %30
%35 = phi i64 [ %19, %27 ], [ %31, %30 ]
%36 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %29, %37
br i1 %38, label %39, label %30
39: ; preds = %34
%40 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %35
store i8 1, i8* %40
%41 = add nsw i32 %26, 1
br label %42
42: ; preds = %30, %24, %39
%43 = phi i32 [ %41, %39 ], [ %26, %24 ], [ %26, %30 ]
%44 = add nuw nsw i64 %25, 1
%45 = icmp eq i64 %44, %21
br i1 %45, label %46, label %24
46: ; preds = %42, %15
%47 = phi i32 [ 0, %15 ], [ %43, %42 ]
%48 = sub nsw i32 %13, %47
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %22, %46
%51 = add nuw nsw i32 %9, 1
%52 = load i32, i32* %1
%53 = icmp slt i32 %51, %52
br i1 %53, label %8, label %54
54: ; preds = %50, %0
ret i32 0
}