#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
const double eps=1e-6;
const double pi=acos(-1.0);
//可以在Point里面用Vec了
class Point;
typedef Point Vec;
//三态函数比较;精度问题
int dcmp(double x){
if(fabs(x)<eps) return 0;
return x<0?-1:1;
}
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
/*
*向量运算
*/
//向量与常数 注意常数要放在后面
Vec operator*(double p){
return Vec(x*p,y*p);
}
Vec operator/(double p){
return Vec(x/p,y/p);
}
//向量与向量
Vec operator-(Vec obj){
return Vec(x-obj.x,y-obj.y);
}
Vec operator+(Vec obj){
return Vec(x+obj.x,y+obj.y);
}
//点积
double operator*(Vec obj){
return x*obj.x+y*obj.y;
}
//叉积
double operator^(Vec obj){
return x*obj.y-y*obj.x;
}
//两个向量的夹角 A*B=|A|*|B|*cos(th)
double Angle(Vec B){
return acos((*this)*B/(*this).len()/B.len());
}
//两条向量平行四边形的面积
double Area(Vec B){
return fabs((*this)^B);//
}
//向量旋转
//旋转公式
// Nx (cos -sin) x
// =
// Ny (sin cos) y
Vec Rotate(double rad){
return Vec(x*cos(rad)-y*sin(rad),x*sin(rad)+y*cos(rad));
}
//返回向量的法向量,即旋转pi/2
Vec Normal(){
//返回单位法向量,注意L不能为0
/*
double L=obj.len();
return Vec(-y/L,x/L);
*/
//返回法向量
return Vec(-y,x);
}
/*
* 向量的性质
*/
//返回向量的长度,或者点距离原点的距离
double len(){
return hypot(x,y);
}
//返回两点之间的距离
double dis(Point obj){
//return hypot(x-obj.x,y-obj.y); //hypot 给定直角三角形的两条直角边,返回斜边边长
return sqrt((x-obj.x)*(x-obj.x)+(y-obj.y)*(y-obj.y));
}
//向量的极角 atan2(y,x)
/*
*向量的关系
*/
bool operator==(Point obj){
return dcmp(x-obj.x)==0&&dcmp(y-obj.y)==0;
}
bool operator<(Point obj){
return x<obj.x||(x==obj.x&&y<obj.y);
}
};
const int maxn=60;
Point A[maxn],B[maxn];
double Min,Max;
double DTS(Point P,Point A,Point B){
if(A==B) return P.dis(A);
Vec v1=B-A,v2=P-A,v3=P-B;
if(dcmp(v1*v2)<0)return v2.len();
if(dcmp(v1*v3)>0)return v3.len();
return fabs(v1^v2/v1.len());
}
void update(Point P,Point A,Point B){
Min=min(Min,DTS(P,A,B));
Max=max(Max,P.dis(A));
Max=max(Max,P.dis(B));
}
/*
2
2 2
0 0 10 0
0 1 10 1
3 2
635 187 241 269 308 254
117 663 760 413
*/
int main(){
int T;
scanf("%d",&T);
rep(kase,0,T){
int num_A,num_B;
scanf("%d %d",&num_A,&num_B);
double x,y;
rep(i,0,num_A)scanf("%lf %lf",&x,&y),A[i]=Point(x,y);
rep(i,0,num_B)scanf("%lf %lf",&x,&y),B[i]=Point(x,y);
//时间一致,可以当做是速度
double len_A=0,len_B=0;
rep(i,0,num_A-1)len_A+=A[i].dis(A[i+1]);
rep(i,0,num_B-1)len_B+=B[i].dis(B[i+1]);
int sa=0,sb=0;
Point pa=A[0],pb=B[0];//正处于哪个点
Min=1e9,Max=-1e9;
while(sa<num_A-1&&sb<num_B-1){
double la=pa.dis(A[sa+1]);
double lb=pb.dis(B[sb+1]);
double t=min(la/len_A,lb/len_B);
Vec va=((A[sa+1]-pa)/la)*(t*len_A);
Vec vb=((B[sb+1]-pb)/lb)*(t*len_B);
update(pa,pb,pb+vb-va);
pa=pa+va;
pb=pb+vb;
if(pa==A[sa+1])++sa;
if(pb==B[sb+1])++sb;
}
printf("Case %d: %.0f\n",kase+1,Max-Min);//等于最近的整数
}
return 0;
}