#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 main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long int n;
    scanf("%ld", &n);
    if (n == 1)
      printf("2\n");
    else {
      long int m;
      m = n / 2;
      if ((m ^ (m + 1)) == n)
        printf("%ld\n", m);
      else
        printf("-1\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11df <main+0xbf>
lea    0xea7(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpq   $0x1,-0x10(%rbp)
jne    1185 <main+0x65>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11da <main+0xba>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
xor    %rcx,%rax
cmp    -0x10(%rbp),%rax
jne    11c7 <main+0xa7>
mov    -0x18(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d5 <main+0xb5>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11da <main+0xba>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1167 <main+0x37>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe95(%rip),%r14
lea    0x8(%rsp),%rbx
lea    0xe95(%rip),%r15
lea    0xe86(%rip),%r12
lea    0xe84(%rip),%r13
jmp    119f <main+0x6f>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
subl   $0x1,0x4(%rsp)
jb     1157 <main+0x27>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%rax
cmp    $0x1,%rax
je     1190 <main+0x60>
mov    %rax,%rsi
shr    $0x3f,%rsi
add    %rax,%rsi
sar    %rsi
lea    0x1(%rsi),%rcx
xor    %rsi,%rcx
cmp    %rax,%rcx
jne    11f0 <main+0xc0>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
subl   $0x1,0x4(%rsp)
jae    119f <main+0x6f>
jmp    1157 <main+0x27>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
jmp    1193 <main+0x63>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [3 x i8] c"2\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@.str.4 = [4 x i8] c"-1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %6
6: ; preds = %31, %0
%7 = load i32, i32* %2
%8 = add nsw i32 %7, -1
store i32 %8, i32* %2
%9 = icmp ne i32 %7, 0
br i1 %9, label %10, label %32
10: ; preds = %6
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%12 = load i64, i64* %3
%13 = icmp eq i64 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %31
16: ; preds = %10
%17 = load i64, i64* %3
%18 = sdiv i64 %17, 2
store i64 %18, i64* %4
%19 = load i64, i64* %4
%20 = load i64, i64* %4
%21 = add nsw i64 %20, 1
%22 = xor i64 %19, %21
%23 = load i64, i64* %3
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i64, i64* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %26)
br label %30
28: ; preds = %16
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
br label %31
31: ; preds = %30, %14
br label %6
32: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@str = [3 x i8] c"-1\00"
@str.5 = [2 x i8] c"2\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i32* %1 to i8*
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add nsw i32 %5, -1
store i32 %6, i32* %1
%7 = icmp eq i32 %5, 0
br i1 %7, label %29, label %8
8: ; preds = %0
%9 = bitcast i64* %2 to i8*
br label %10
10: ; preds = %8, %25
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%12 = load i64, i64* %2
%13 = icmp eq i64 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
br label %25
16: ; preds = %10
%17 = sdiv i64 %12, 2
%18 = add nsw i64 %17, 1
%19 = xor i64 %18, %17
%20 = icmp eq i64 %19, %12
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %17)
br label %25
23: ; preds = %16
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %21, %23, %14
%26 = load i32, i32* %1
%27 = add nsw i32 %26, -1
store i32 %27, i32* %1
%28 = icmp eq i32 %26, 0
br i1 %28, label %29, label %10
29: ; preds = %25, %0
ret i32 0
}