#include<bits/stdc++.h>
#define mx 109
#define inf 1e8
#define nil -999999999
using namespace std;
typedef long long ll;
ll graph[mx][mx];
ll path[mx][mx];
ll edge,node,idx;
void initialize_path()
{
ll i,j,k,l,m,n;
for(i=0;i<mx;i++)
{
for(j=0;j<=mx;j++)
{
if(graph[i][j]==inf)
{
path[i][j]=nil;
}
else
{
path[i][j]=i;
}
}
}
return;
}
void solve()
{
ll i,j,k,l,m,n;
cin>>node>>edge;
for(i=0;i<mx;i++)
{
for(j=0;j<mx;j++)
{
graph[i][j]=inf;
}
}
for(i=0;i<=edge;i++)
{
graph[i][i]=0;
}
for(i=0;i<mx;i++)
{
for(j=0;j<mx;j++)
{
if(i==j)
{
graph[i][j]=0;
continue;
}
graph[i][j]=inf;
}
}
for(i=1;i<=edge;i++)
{
ll a,b,cost;
cin>>a>>b;
cost=1;
graph[a][b]=cost;
graph[b][a]=cost;
}
for(k=0;k<node;k++)
{
for(i=0;i<node;i++)
{
for(j=0;j<node;j++)
{
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
}
}
}
ll st,ed;
cin>>st>>ed;
ll mxx=-9999;
for(i=0;i<node;i++)
{
ll tmp=graph[i][st]+graph[i][ed];
if(tmp>mxx)
{
mxx=tmp;
}
}
cout<<"Case "<<idx<<": "<<mxx<<endl;
idx++;
return;
}
int main()
{
ll i,j,k,l,m,n,test;
cin>>test;
idx=1;
for(k=1;k<=test;k++)
{
solve();
}
return 0;
}
#define mx 109
#define inf 1e8
#define nil -999999999
using namespace std;
typedef long long ll;
ll graph[mx][mx];
ll path[mx][mx];
ll edge,node,idx;
void initialize_path()
{
ll i,j,k,l,m,n;
for(i=0;i<mx;i++)
{
for(j=0;j<=mx;j++)
{
if(graph[i][j]==inf)
{
path[i][j]=nil;
}
else
{
path[i][j]=i;
}
}
}
return;
}
void solve()
{
ll i,j,k,l,m,n;
cin>>node>>edge;
for(i=0;i<mx;i++)
{
for(j=0;j<mx;j++)
{
graph[i][j]=inf;
}
}
for(i=0;i<=edge;i++)
{
graph[i][i]=0;
}
for(i=0;i<mx;i++)
{
for(j=0;j<mx;j++)
{
if(i==j)
{
graph[i][j]=0;
continue;
}
graph[i][j]=inf;
}
}
for(i=1;i<=edge;i++)
{
ll a,b,cost;
cin>>a>>b;
cost=1;
graph[a][b]=cost;
graph[b][a]=cost;
}
for(k=0;k<node;k++)
{
for(i=0;i<node;i++)
{
for(j=0;j<node;j++)
{
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
}
}
}
ll st,ed;
cin>>st>>ed;
ll mxx=-9999;
for(i=0;i<node;i++)
{
ll tmp=graph[i][st]+graph[i][ed];
if(tmp>mxx)
{
mxx=tmp;
}
}
cout<<"Case "<<idx<<": "<<mxx<<endl;
idx++;
return;
}
int main()
{
ll i,j,k,l,m,n,test;
cin>>test;
idx=1;
for(k=1;k<=test;k++)
{
solve();
}
return 0;
}