#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 intersect(int **, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ sorti(int **, int);
int /*<<< orphan*/ sortj(int **, int);
int main() {
  int t, N, i, j, count, temp;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &N);
    int arr[N][2];
    for (i = 0; i < N; i++)
      scanf("%d %d", &arr[i][0], &arr[i][1]);
    sorti(arr, N);
    sortj(arr, N);
    printf("%d\n", intersect(arr, N));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9d(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     124c <main+0xfc>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120e <main+0xbe>
mov    -0x38(%rbp),%rdx
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %rdx,%rsi
add    %rax,%rsi
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
add    $0x4,%rdx
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c5 <main+0x75>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <sorti@plt>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <sortj@plt>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <intersect@plt>
mov    %eax,%esi
lea    0xdcb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    1171 <main+0x21>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,-0x30(%rbp)
jae    1187 <main+0x37>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe72(%rip),%r13
jmp    11c5 <main+0x75>
mov    %r14,%rdi
call   1030 <sorti@plt>
mov    -0x2c(%rbp),%esi
mov    %r14,%rdi
call   1050 <sortj@plt>
mov    -0x2c(%rbp),%esi
mov    %r14,%rdi
call   1070 <intersect@plt>
lea    0xe51(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r15,%rsp
subl   $0x1,-0x30(%rbp)
jb     1176 <main+0x26>
lea    0xe37(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    1190 <main+0x40>
mov    %r14,%rbx
xor    %r12d,%r12d
nop
lea    0x4(%rbx),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r12
movslq -0x2c(%rbp),%rsi
add    $0x8,%rbx
cmp    %rsi,%r12
jl     1200 <main+0xb0>
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%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 i8*
%9 = alloca i64
store i32 0, i32* %1
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %11
11: ; preds = %38, %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 %50
15: ; preds = %11
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %3
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %8
%20 = alloca [2 x i32], i64 %18
store i64 %18, i64* %9
store i32 0, i32* %4
br label %21
21: ; preds = %35, %15
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 %27
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %28, i64 0, i64 0
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 %31
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %32, i64 0, i64 1
%34 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %29, i32* %33)
br label %35
35: ; preds = %25
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %21
38: ; preds = %21
%39 = bitcast [2 x i32]* %20 to i32**
%40 = load i32, i32* %3
%41 = call i32 @sorti(i32** %39, i32 %40)
%42 = bitcast [2 x i32]* %20 to i32**
%43 = load i32, i32* %3
%44 = call i32 @sortj(i32** %42, i32 %43)
%45 = bitcast [2 x i32]* %20 to i32**
%46 = load i32, i32* %3
%47 = call i32 @intersect(i32** %45, i32 %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i8*, i8** %8
br label %11
50: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %39, label %9
9: ; preds = %0, %28
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
%14 = alloca i32*, i64 %12
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %9, %17
%18 = phi i64 [ %24, %17 ], [ 0, %9 ]
%19 = getelementptr inbounds i32*, i32** %14, i64 %18
%20 = bitcast i32** %19 to [2 x i32]*
%21 = bitcast i32** %19 to i32*
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %21, i32* %22)
%24 = add nuw nsw i64 %18, 1
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %17, label %28
28: ; preds = %17, %9
%29 = phi i32 [ %15, %9 ], [ %25, %17 ]
%30 = call i32 @sorti(i32** %14, i32 %29)
%31 = load i32, i32* %2
%32 = call i32 @sortj(i32** %14, i32 %31)
%33 = load i32, i32* %2
%34 = call i32 @intersect(i32** %14, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %1
%37 = add nsw i32 %36, -1
store i32 %37, i32* %1
%38 = icmp eq i32 %36, 0
br i1 %38, label %39, label %9
39: ; preds = %28, %0
ret i32 0
}