//注意了一种情况: 城市 x 没有airpot,但是有无聊人想从x到x 那么结果不是1,而是0
//排除了这种坑爹情况后就是简单的Dijkstra了
/* ID:1192432 PROG: castle LANG: C++ */ #include <iostream> #include <string> #include <map> #include <vector> #include <memory.h> #include <cstdio> #include <cmath> #include <queue> #include <algorithm> using namespace std; typedef pair<int,int> pii; const int MAX=10005,INF=1<<30,w=1; bool city[2005], done[2005]; int n,m,k,Q,l, first[2005],next[MAX*2],d[2005], u[MAX*2],v[MAX*2]; priority_queue<pii,vector<pii>,greater<pii> > q; void work(int sta,int end){ if(sta==end){ cout<<0<<endl; return ; } int U,dis; pii x; memset(done,0,sizeof(done)); for(int i=1;i<=n;i++) d[i]=INF; if(city[sta]) dis=0; else dis=1; d[sta]=dis; q.push(make_pair(dis,sta)); while(!q.empty()){ x=q.top(); q.pop(); U=x.second; if(done[U]) continue; done[U]=1; //cout<<"U: "<<U<<endl; for(int e=first[U];e!=-1;e=next[e]){ if(city[v[e]]) dis=0; else dis=1; if(d[v[e]]>d[U]+dis){ d[v[e]]=d[U]+dis; //fa[v[e]]=U; q.push(make_pair(d[v[e]],v[e])); } } } if(d[end]==INF) cout<<-1<<endl; else cout<<d[end]<<endl; return ; } int main() { freopen("i.txt","r",stdin); //freopen("castle.in","r",stdin); //freopen("castle.out","w",stdout); int nCase,t,t1,t2,num=1; cin>>nCase; while(nCase--){ //if(num!=1) // cout<<endl; cout<<"Case "<<num++<<":"<<endl; l=0; cin>>n>>m>>k; memset(city,0,sizeof(city)); memset(first,-1,sizeof(first)); //memset(next,-1,sizeof(next)); for(int i=0;i<k;i++){ cin>>t; city[t]=1; } for(int i=0;i<m;i++){ cin>>t1>>t2; u[l]=t1; v[l]=t2; next[l]=first[u[l]]; first[u[l]]=l; ++l; u[l]=t2; v[l]=t1; next[l]=first[u[l]]; first[u[l]]=l; ++l; } cin>>Q; for(int i=0;i<Q;i++){ cin>>t1>>t2; work(t1,t2); } cout<<endl; } return 0; }