#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

struct state{
  int y,x,c,n,d;
  state(int y=0, int x=0, int c=0, int n=0, int d=0):y(y),x(x),c(c),n(n),d(d){}
  bool operator < (const state &s) const {
    return c > s.c;
  }
};

const int INF = 1 << 29;
const int N = 21;
const int dy[4] = {0,1,0,-1};
const int dx[4] = {1,0,-1,0};
int h,w,dis,ns,nc,nj,G[N][N][N][N],sig[N][N],sx,sy,gx,gy;

bool check(int y, int x){
  if(y < 0 || y >= h) return false;
  if(x < 0 || x >= w) return false;
  return true;
}

int strnum(string str){
  int c = 0;
  for(int i=2;i<str.size();i++){
    c *= 10;
    c += str[i] - '0';
  }
  c--;
  return c;
}

void solve(){
  int d[N][N][101][4];
  priority_queue<state> Q;
  state u,v;
  for(int i=0;i<N*N;i++) for(int j=0;j<101;j++) for(int k=0;k<4;k++) d[i/N][i%N][j][k] = INF;
  for(int i=0;i<4;i++){
    if(i == 2) continue;
    Q.push(state(sy,sx,0,0,i));
  }
  while(!Q.empty()){
    u = Q.top();
    Q.pop();
    if(gy == u.y && gx == u.x){
      cout << u.c << endl;
      return;
    }

    v = state(u.y+dy[u.d], u.x+dx[u.d], u.c, u.n+1, u.d);
    if(!check(v.y, v.x) ||  v.n > 100) continue;
    if(sig[v.y][v.x] > 0 && (v.n / sig[v.y][v.x]) % 2 == u.d % 2) continue;
    v.c += G[u.y][u.x][v.y][v.x];
    if(d[v.y][v.x][v.n][u.d] <= v.c) continue;
    d[v.y][v.x][v.n][u.d] = v.c;
    for(int i=0;i<4;i++){
      if(i == 2) continue;
      v.d = (u.d + i) % 4;
      Q.push(v);
    }
  }
}

int main(){
  while(cin >> h >> w && (h|w)){
    string str,str2;
    for(int i=0;i<N*N;i++) for(int j=0;j<N*N;j++) G[i/N][i%N][j/N][j%N] = INF;
    fill(sig[0],sig[N],0);
    cin >> dis;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	for(int k=0;k<4;k++)
	  if(check(i+dy[k], j+dx[k]))
	    G[i][j][i+dy[k]][j+dx[k]] = dis;
    cin >> ns;
    for(int i=0;i<ns;i++){
      cin >> str;
      cin >> sig[str[0]-'a'][strnum(str)];
    }
    cin >> nc;
    for(int i=0;i<nc;i++){
      cin >> str >> str2;
      G[str[0]-'a'][strnum(str)][str2[0]-'a'][strnum(str2)] = G[str2[0]-'a'][strnum(str2)][str[0]-'a'][strnum(str)] = INF;
    }
    cin >> nj;
    for(int i=0;i<nj;i++){
      int c;
      cin >> str >> str2 >> c;
      G[str[0]-'a'][strnum(str)][str2[0]-'a'][strnum(str2)] = G[str2[0]-'a'][strnum(str2)][str[0]-'a'][strnum(str)] += c;
    }
    cin >> str >> str2;
    sy = str[0] - 'a';
    sx = strnum(str);
    gy = str2[0] - 'a';
    gx = strnum(str2);

    solve();
  }
}