#include <iostream>
#include <stdio.h>
#include <queue>
#include <string.h>

using namespace std;
#define inf 10000000000000

__int64 map[101][101];
__int64 d[101];
bool hash[101];
__int64 a[101];
__int64 l1,l2,l3,l4,c1,c2,c3,c4;
__int64 n,m;
__int64 start,end;

struct node{
   __int64 adj;
   __int64 weight;
   node* next;
}node,*pnode;

struct Heap{
   bool operator<(Heap T)const{
      return T.dis < dis;
   }

   __int64 x;
   __int64 dis;
};

priority_queue<Heap> Q;

__int64 bfs(){
   __int64 i;

   for(i = 0 ; i <= 100 ; ++i){
      hash[i] = 0;
      d[i] = inf;
   }
   Heap min,in;
   while(!Q.empty()){
      Q.pop();
   }

   in.x = start;
   in.dis = 0;
   d[start] = 0;
   Q.push(in);
   while(!Q.empty()){
       min = Q.top();
       Q.pop();

       if(min.x == end){
        return min.dis;
       }

       if(hash[min.x]){
        continue;
       }

       hash[min.x] = true;

       for(i = 1 ; i <= n ; ++i){
          if(d[i] > d[min.x] + map[min.x][i] && !hash[i]){
            in.x = i;
            in.dis = map[min.x][i] + d[min.x];
            d[i] = in.dis;
            Q.push(in);
          }
       }
   }

   return -1;

}

int judge(int dis){
   if(dis > 0 && dis <= l1){
      return c1;
   }else{
      if(dis >l1 && dis <= l2){
        return c2;
      }else{
          if(dis > l2 && dis <=l3){
            return c3;
          }else if(dis > l3 && dis <= l4){
            return c4;
          }else{
            return -1;
          }
      }
   }
}

int main(){
    int t;
    scanf("%d",&t);
    int p = 1;

    while(t--){
        scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
        scanf("%I64d%I64d",&n,&m);

         __int64 i,j;
        for(i = 1 ; i <= n ; ++i){
            for(j = 1 ; j <= n ; ++j){
                map[i][j] = inf;
            }
        }

        for(i = 1 ; i <=n ; ++i){
            scanf("%I64d",&a[i]);
        }

        for(i = 1 ; i <= n ; ++i){
            for(j = 1 ; j <= n ; ++j){

                // a[i] - a[j] :计算站于占志坚的距离
                __int64 l = a[i] - a[j];
                if( l < 0){
                    l = -l;
                }

                //judge(l) :计算这个距离所对应的费用
                __int64 s = judge(l);

                if(s < 0){
                    s = inf;
                }


                map[i][j] = s;
                map[j][i] = s;
            }
        }

        printf("Case %d:\n",p++);
        for(i = 1 ; i <= m ; ++i){
            scanf("%I64d%I64d",&start,&end);
            bfs();
            if(d[end] == inf){
                printf("Station %I64d and station %I64d are not attainable.\n",start,end);
            }else{
               printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",start,end,d[end]);
            }
        }


    }
}