import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;
/**
* @author Ryan
* @data 2020/05/07 - 周四
*/
public class 袭击119 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
int N = sc.nextInt();
MyPoint[] ps = new MyPoint[2 * N];
MyPoint p;
double x, y;
double dist = Double.MAX_VALUE;
for (int j = 0; j < N; j++) {
x = sc.nextDouble();
y = sc.nextDouble();
p = new MyPoint(x, y, 1);
ps[j] = p;
}
for (int j = 0; j < N; j++) {
x = sc.nextInt();
y = sc.nextInt();
p = new MyPoint(x, y, 2);
ps[N + j] = p;
}
if (dist < 1) {
System.out.printf("%.3f %n", dist);
}
Arrays.sort(ps, comp);
dist = findMinDist(ps, 0, 2 * N - 1);
System.out.printf("%.3f %n", Math.sqrt(dist));
}
}
static Comparator<MyPoint> comp = new Comparator<MyPoint>() {
@Override
public int compare(MyPoint a1, MyPoint a2) {
return a1.x-a2.x > 0 ? 1:-1;
}};
private static double findMinDist(MyPoint[] ps, int l, int r) {
int mid = l + (r - l) / 2;
double min = Double.MAX_VALUE;
if (l >= r) {
return min;
} else if (l + 1 == r) {
return calculateDist(ps[l], ps[r]);
}
min = Math.min(findMinDist(ps, l, mid), findMinDist(ps,mid +1, r));
int cnt = 0;
MyPoint[] t = new MyPoint[r - l + 1];
double lowBound = ps[mid].x - Math.sqrt(min);
double upBound = ps[mid].x + Math.sqrt(min);
for (int i = l; i <= r; i++) {
if (ps[i].x >= lowBound && ps[i].x <= upBound) {
t[cnt++] = ps[i];
}
}
double team = 0;
for (int i = 0; i < cnt - 1; i++) {
for (int j = i + 1; j < cnt ; j++) {
team = calculateDist(ps[i], ps[j]);
min = Math.min(min, team);
}
}
return min;
}
private static double calculateDist(MyPoint p, MyPoint p1) {
if (p1.f == p.f) {
return Double.MAX_VALUE;
}
return (p.x - p1.x) * (p.x - p1.x) + (p.y - p1.y) * (p.y - p1.y);
}
static class MyPoint {
double x;
double y;
int f;
public MyPoint(double x, double y, int f) {
this.x = x;
this.y = y;
this.f = f;
}
}
}