#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define N 1005 #define INF 200000000000 #define LL __int64 LL ma[N][N],d[N],vis[N],dis[N]; LL dijkstral(LL v0,LL n,LL t) { LL v,x,y,temp,i; for(i = 1 ; i <= n ; i++) { d[i] = ma[v0][i]; vis[i] = 0; } d[v0] = 0; vis[v0] = 1; for(i = 1 ; i <= n ; i++) { temp = INF; for(y = 1 ; y <= n ;y++) if(!vis[y]&&temp>d[y]) temp = d[x=y]; if(temp == INF) return d[t]; vis[x] = 1; for(y = 1 ; y <= n ; y++) if(!vis[y]&&d[x]+ma[x][y]<d[y]) d[y] = d[x]+ma[x][y]; } return d[t]; } int main() { LL n,m,i,j,k,s,ed,L1,L2,L3,L4,C1,C2,C3,C4,t,cas = 1; scanf("%I64d",&t); while(t--) { scanf("%I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d",&L1,&L2,&L3,&L4,&C1,&C2,&C3,&C4); scanf("%I64d %I64d",&n,&m); for(i = 1; i <= n ; i++) scanf("%I64d",&dis[i]); for(i = 1 ; i <= n ; i++) for(j = i+1 ; j <= n ; j++) { LL ans = abs(dis[i]-dis[j]); if(ans>0&&ans<=L1) ma[i][j] = ma[j][i] = C1; else if(ans>L1&&ans<=L2) ma[i][j] = ma[j][i] = C2; else if(ans>L2&&ans<=L3) ma[i][j] = ma[j][i] = C3; else if(ans>L3&&ans<=L4) ma[i][j] = ma[j][i] = C4; else ma[i][j] = ma[j][i] = INF; } printf("Case %d: ",cas++); while(m--) { scanf("%I64d %I64d",&s,&ed); LL res = dijkstral(s,n,ed); if(res!=INF) printf("The minimum cost between station %I64d and station %I64d is %I64d. ",s,ed,res); else printf("Station %I64d and station %I64d are not attainable. ",s,ed); } } return 0; }