#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <string>
using namespace std;
int N;
double E;
long long node[1000][2]; //i, j 저장
long long adj[1000][1000]; // i <-> j의 비용
int main() {
int tcm;
scanf("%d", &tcm);
for (int tc = 1; tc <= tcm; tc++) {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%lld", &node[i][0]);
}
for (int i = 0; i < N; i++) {
scanf("%lld", &node[i][1]);
}
scanf("%lf", &E);
for (int i = 0; i < N; i++) {
long long nowi = node[i][0];
long long nowj = node[i][1];
for (int j = 0; j < N; j++) {
if (i == j) continue;
long long nexti = node[j][0];
long long nextj = node[j][1];
long long weight = ((nowi - nexti) * (nowi - nexti)) + (nowj - nextj) * (nowj - nextj);
adj[i][j] = weight;
adj[j][i] = weight;
}
}
vector<long long> isVisit = vector<long long>();
bool isVisitArr[1000];
for (int i = 0; i < 1000; i++) {
isVisitArr[i] = false;
}
isVisit.push_back(0);
isVisitArr[0] = true;
long long allWeight = 0;
while (isVisit.size() < N) {
int next = 0;
long long minWeight = -1;
for (auto now : isVisit) {
for (int i = 0; i < N; i++) {
if (i == now) continue;
if (isVisitArr[i]) continue;
if (minWeight == -1 || adj[now][i] < minWeight) {
minWeight = adj[now][i];
next = i;
}
}
}
allWeight += minWeight;
//cout << "MIN : " << minWeight << " , ALL : " << allWeight << endl;
isVisitArr[next] = true;
isVisit.push_back(next);
}
printf("#%d %lld\n", tc, (long long)round(E * allWeight));
cout << "";
}
return 0;
}