#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ connect_D();
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ init_DM();
int /*<<< orphan*/ portal_D(int, int);
int /*<<< orphan*/ printf(char *, int);
int solve();
void load(FILE *in) {
  int T, NL, NS;
  fscanf(in, "%d\n", &T);
  for (int i = 0; i < T; i++) {
    init_DM();
    fscanf(in, "%d\n", &NL);
    for (int l = 0; l < NL; l++) {
      int a, b;
      fscanf(in, "%d %d\n", &a, &b);
      portal_D(a - 1, b - 1);
    }
    fscanf(in, "%d\n", &NS);
    for (int s = 0; s < NS; s++) {
      int a, b;
      fscanf(in, "%d %d\n", &a, &b);
      portal_D(a - 1, b - 1);
    }
    connect_D();
    printf("%d\n", solve());
  }
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    128a <load+0x12a>
mov    $0x0,%al
call   1060 <init_DM@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5c(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fe <load+0x9e>
mov    -0x8(%rbp),%rdi
lea    0xe30(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x20(%rbp),%edi
sub    $0x1,%edi
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
call   1040 <portal_D@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b9 <load+0x59>
mov    -0x8(%rbp),%rdi
lea    0xdfa(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1260 <load+0x100>
mov    -0x8(%rbp),%rdi
lea    0xdce(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x2c(%rbp),%edi
sub    $0x1,%edi
mov    -0x30(%rbp),%esi
sub    $0x1,%esi
call   1040 <portal_D@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    121b <load+0xbb>
mov    $0x0,%al
call   1080 <connect_D@plt>
mov    $0x0,%al
call   1030 <solve@plt>
mov    %eax,%esi
lea    0xd8c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <load+0x29>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe8b(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
cmpl   $0x0,0x10(%rsp)
jle    12a3 <load+0x143>
lea    0xe6d(%rip),%r14
lea    0xe63(%rip),%r12
lea    0x4(%rsp),%r13
mov    %rsp,%r15
xor    %eax,%eax
jmp    11d9 <load+0x79>
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <connect_D@plt>
xor    %eax,%eax
call   1030 <solve@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x14(%rsp),%eax
add    $0x1,%eax
cmp    0x10(%rsp),%eax
jge    12a3 <load+0x143>
mov    %eax,0x14(%rsp)
xor    %eax,%eax
call   1060 <init_DM@plt>
mov    %rbx,%rdi
mov    %r14,%rbp
mov    %r14,%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1240 <load+0xe0>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x4(%rsp),%edi
add    $0xffffffff,%edi
mov    (%rsp),%esi
add    $0xffffffff,%esi
call   1040 <portal_D@plt>
add    $0x1,%r14d
cmp    0xc(%rsp),%r14d
jl     1210 <load+0xb0>
mov    %rbx,%rdi
mov    %rbp,%r14
mov    %rbp,%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11b0 <load+0x50>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x4(%rsp),%edi
add    $0xffffffff,%edi
mov    (%rsp),%esi
add    $0xffffffff,%esi
call   1040 <portal_D@plt>
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jl     1270 <load+0x110>
jmp    11b0 <load+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define void @load(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %2
%13 = load i32*, i32** %2
%14 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %6
br label %15
15: ; preds = %60, %1
%16 = load i32, i32* %6
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %63
19: ; preds = %15
%20 = call i32 (...) @init_DM()
%21 = load i32*, i32** %2
%22 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
store i32 0, i32* %7
br label %23
23: ; preds = %35, %19
%24 = load i32, i32* %7
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i32*, i32** %2
%29 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %8, i32* %9)
%30 = load i32, i32* %8
%31 = sub nsw i32 %30, 1
%32 = load i32, i32* %9
%33 = sub nsw i32 %32, 1
%34 = call i32 @portal_D(i32 %31, i32 %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %23
38: ; preds = %23
%39 = load i32*, i32** %2
%40 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %5)
store i32 0, i32* %10
br label %41
41: ; preds = %53, %38
%42 = load i32, i32* %10
%43 = load i32, i32* %5
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = load i32*, i32** %2
%47 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %11, i32* %12)
%48 = load i32, i32* %11
%49 = sub nsw i32 %48, 1
%50 = load i32, i32* %12
%51 = sub nsw i32 %50, 1
%52 = call i32 @portal_D(i32 %49, i32 %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %41
56: ; preds = %41
%57 = call i32 (...) @connect_D()
%58 = call i32 (...) @solve()
%59 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %56
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %15
63: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define void @load(i32* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = bitcast i32* %5 to i8*
%17 = bitcast i32* %6 to i8*
%18 = bitcast i32* %7 to i8*
%19 = bitcast i32* %8 to i8*
br label %21
20: ; preds = %42, %1
ret void
21: ; preds = %15, %42
%22 = phi i32 [ 0, %15 ], [ %46, %42 ]
%23 = call i32 (...) @init_DM()
%24 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %3
%26 = icmp sgt i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %31, %21
%28 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, 0
br i1 %30, label %49, label %42
31: ; preds = %21, %31
%32 = phi i32 [ %39, %31 ], [ 0, %21 ]
%33 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %6)
%34 = load i32, i32* %5
%35 = add nsw i32 %34, -1
%36 = load i32, i32* %6
%37 = add nsw i32 %36, -1
%38 = call i32 @portal_D(i32 %35, i32 %37)
%39 = add nuw nsw i32 %32, 1
%40 = load i32, i32* %3
%41 = icmp slt i32 %39, %40
br i1 %41, label %31, label %27
42: ; preds = %49, %27
%43 = call i32 (...) @connect_D()
%44 = call i32 (...) @solve()
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = add nuw nsw i32 %22, 1
%47 = load i32, i32* %2
%48 = icmp slt i32 %46, %47
br i1 %48, label %21, label %20
49: ; preds = %27, %49
%50 = phi i32 [ %57, %49 ], [ 0, %27 ]
%51 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %8)
%52 = load i32, i32* %7
%53 = add nsw i32 %52, -1
%54 = load i32, i32* %8
%55 = add nsw i32 %54, -1
%56 = call i32 @portal_D(i32 %53, i32 %55)
%57 = add nuw nsw i32 %50, 1
%58 = load i32, i32* %4
%59 = icmp slt i32 %57, %58
br i1 %59, label %49, label %42
}