#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*/ fill_dist(int, int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int tsp(int, int *);
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int x, y;
    scanf("%d %d", &x, &y);
    scanf("%d %d", &x, &y);
    int n;
    scanf("%d", &n);
    n++;
    int dist[n * n];
    fill_dist(n, dist, x, y);
    printf("%d\n", tsp(n, dist));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xead(%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     1228 <main+0xe8>
lea    0xe84(%rip),%rdi
mov    %rdi,-0x50(%rbp)
xor    %eax,%eax
mov    %al,-0x31(%rbp)
lea    -0xc(%rbp),%rsi
mov    %rsi,-0x48(%rbp)
lea    -0x10(%rbp),%rdx
mov    %rdx,-0x40(%rbp)
call   1060 <scanf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x31(%rbp),%al
call   1060 <scanf@plt>
mov    -0x31(%rbp),%al
lea    0xe4b(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x30(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <fill_dist@plt>
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edi
call   1030 <tsp@plt>
mov    %eax,%esi
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    1161 <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
sub    $0x18,%rsp
lea    0xeab(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,-0x30(%rbp)
jb     120d <main+0xcd>
lea    0xe8c(%rip),%r14
lea    -0x38(%rbp),%r15
lea    -0x34(%rbp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe5c(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
imul   %eax,%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    %r13,%rsi
call   1050 <fill_dist@plt>
mov    -0x2c(%rbp),%edi
mov    %r13,%rsi
call   1030 <tsp@plt>
lea    0xe0d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r12,%rsp
subl   $0x1,-0x30(%rbp)
jae    1180 <main+0x40>
xor    %eax,%eax
lea    -0x28(%rbp),%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 = [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 i8*
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %33
13: ; preds = %9
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = load i32, i32* %5
%21 = mul nsw i32 %19, %20
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %6
%24 = alloca i32, i64 %22
store i64 %22, i64* %7
%25 = load i32, i32* %5
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @fill_dist(i32 %25, i32* %24, i32 %26, i32 %27)
%29 = load i32, i32* %5
%30 = call i32 @tsp(i32 %29, i32* %24)
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i8*, i8** %6
br label %9
33: ; preds = %9
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 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = call i32 (i8*, i32*, ...) @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 %34, label %10
10: ; preds = %0
%11 = bitcast i32* %2 to i8*
%12 = bitcast i32* %3 to i8*
%13 = bitcast i32* %4 to i8*
br label %14
14: ; preds = %10, %14
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = mul nsw i32 %19, %19
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i32, i64 %21
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = call i32 @fill_dist(i32 %24, i32* %23, i32 %25, i32 %26)
%28 = load i32, i32* %4
%29 = call i32 @tsp(i32 %28, i32* %23)
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %1
%32 = add nsw i32 %31, -1
store i32 %32, i32* %1
%33 = icmp eq i32 %31, 0
br i1 %33, label %34, label %14
34: ; preds = %14, %0
ret i32 0
}