#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--) {
    unsigned long long int min = 0, max = 0, inner, outer;
    int n, i, pos;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%lld", &inner);
      scanf("%lld", &outer);
      if (inner > min) {
        pos = i;
        min = inner;
      } else if (outer > max)
        max = outer;
    }
    if (min > max)
      printf("%d\n", pos + 1);
    else
      printf("-1\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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     1237 <main+0x117>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe94(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11fd <main+0xdd>
lea    0xe72(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe60(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11cf <main+0xaf>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11ea <main+0xca>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11e5 <main+0xc5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ea <main+0xca>
jmp    11ef <main+0xcf>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    117e <main+0x5e>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1224 <main+0x104>
mov    -0x34(%rbp),%esi
add    $0x1,%esi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <main+0x112>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x40,%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    0xebb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0x4(%rsp)
jb     121e <main+0xee>
lea    0xea0(%rip),%r13
lea    0x8(%rsp),%rbx
jmp    1187 <main+0x57>
nopw   0x0(%rax,%rax,1)
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
subl   $0x1,0x4(%rsp)
jb     121e <main+0xee>
lea    0xe72(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,(%rsp)
jle    1170 <main+0x40>
xor    %r14d,%r14d
xor    %eax,%eax
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%r12
mov    %r13,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%rax
cmp    %r12,%rax
cmovbe %r12,%rax
cmp    %r15,%rcx
cmova  %rcx,%r15
cmova  %r12,%rax
cmova  %r14d,%ebp
add    $0x1,%r14d
cmp    (%rsp),%r14d
jl     11b0 <main+0x80>
cmp    %rax,%r15
jbe    1170 <main+0x40>
lea    0x1(%rbp),%esi
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
subl   $0x1,0x4(%rsp)
jae    1187 <main+0x57>
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 = [5 x i8] c"%lld\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [4 x i8] c"-1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %11
11: ; preds = %51, %0
%12 = load i32, i32* %2
%13 = add nsw i32 %12, -1
store i32 %13, i32* %2
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %52
15: ; preds = %11
store i64 0, i64* %3
store i64 0, i64* %4
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 0, i32* %8
br label %17
17: ; preds = %38, %15
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %6)
%24 = load i64, i64* %5
%25 = load i64, i64* %3
%26 = icmp ugt i64 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* %8
store i32 %28, i32* %9
%29 = load i64, i64* %5
store i64 %29, i64* %3
br label %37
30: ; preds = %21
%31 = load i64, i64* %6
%32 = load i64, i64* %4
%33 = icmp ugt i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = load i64, i64* %6
store i64 %35, i64* %4
br label %36
36: ; preds = %34, %30
br label %37
37: ; preds = %36, %27
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %17
41: ; preds = %17
%42 = load i64, i64* %3
%43 = load i64, i64* %4
%44 = icmp ugt i64 %42, %43
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %51
49: ; preds = %41
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
br label %11
52: ; preds = %11
ret i32 0
}

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