#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 heightOfNode(int);
int max(int, int);
int numberOfNodesInCompleteBinaryTree(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int numCases;
  int numGenerations, nodeA, nodeB, heightA, heightB, numDistinctNodes;
  scanf("%d", &numCases);
  while (numCases) {
    scanf("%d %d %d", &numGenerations, &nodeA, &nodeB);
    heightA = heightOfNode(nodeA);
    heightB = heightOfNode(nodeB);
    numDistinctNodes = numberOfNodesInCompleteBinaryTree(numGenerations) -
                       numberOfNodesInCompleteBinaryTree(
                           numGenerations - max(heightA, heightB) + 1) +
                       1;
    printf("%d\n", numDistinctNodes);
    numCases--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11fe <main+0xae>
lea    0xe7e(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x10(%rbp),%edi
call   1060 <heightOfNode@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <heightOfNode@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <numberOfNodesInCompleteBinaryTree@plt>
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <max@plt>
mov    -0x28(%rbp),%edi
sub    %eax,%edi
add    $0x1,%edi
call   1030 <numberOfNodesInCompleteBinaryTree@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1171 <main+0x21>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea1(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
je     1205 <main+0xb5>
lea    0x10(%rsp),%r13
lea    0xe81(%rip),%rbx
nopl   0x0(%rax,%rax,1)
lea    0xe69(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x14(%rsp),%edi
call   1060 <heightOfNode@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%edi
call   1060 <heightOfNode@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%edi
call   1030 <numberOfNodesInCompleteBinaryTree@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%r12d
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <max@plt>
sub    %eax,%r12d
add    $0x1,%r12d
mov    %r12d,%edi
call   1030 <numberOfNodesInCompleteBinaryTree@plt>
sub    %eax,%r15d
add    $0x1,%r15d
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
addl   $0xffffffff,0xc(%rsp)
jne    1190 <main+0x40>
xor    %eax,%eax
add    $0x18,%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 = [9 x i8] c"%d %d %d\00"
@.str.2 = [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 i32
store i32 0, i32* %1
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%15 = load i32, i32* %4
%16 = call i32 @heightOfNode(i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = call i32 @heightOfNode(i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %3
%20 = call i32 @numberOfNodesInCompleteBinaryTree(i32 %19)
%21 = load i32, i32* %3
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = call i32 @max(i32 %22, i32 %23)
%25 = sub nsw i32 %21, %24
%26 = add nsw i32 %25, 1
%27 = call i32 @numberOfNodesInCompleteBinaryTree(i32 %26)
%28 = sub nsw i32 %20, %27
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %2
%33 = add nsw i32 %32, -1
store i32 %33, i32* %2
br label %10
34: ; preds = %10
ret i32 0
}

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