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

typedef pair<int,int> P1;
typedef pair<P1,P1> P2;

int main(){
  int i,k;
  bool mint[20][20][4][101];
  int sig[20][20],cost[20][20][20][20];
  int m,n,d,ns,nc,nj,sw,sh,gw,gh;
  char c,t;

  for(;;){
    cin >> m >> n;
    if(!m && !n)break;

    cin >> d;
    fill(&cost[0][0][0][0],&cost[m-1][n-1][m-1][n-1]+1,d);

    cin >> ns;
    fill(&sig[0][0],&sig[m-1][n-1]+1,0);
    for(i=0;i<ns;i++){
      cin >> c >> t >> sw >> k;
      sh = c-'a';
      sig[sh][sw-1] = k;
    }

    cin >> nc;
    for(i=0;i<nc;i++){
      cin >> c >> t >> sw;
      sh = c-'a';
      cin >> c >> t >> gw;
      gh = c-'a';
      cost[sh][sw-1][gh][gw-1] = -1;
      cost[gh][gw-1][sh][sw-1] = -1;
    }

    cin >> nj;
    for(i=0;i<nj;i++){
      cin >> c >> t >> sw;
      sh = c-'a';
      cin >> c >> t >> gw;
      gh = c-'a';
      cin >> k;
      cost[sh][sw-1][gh][gw-1] += k;
      cost[gh][gw-1][sh][sw-1] += k;
    }

    cin >> c >> t >> sw;
    sh = c-'a';
    sw--;
    cin >> c >> t >> gw;
    gh = c-'a';
    gw--;

    fill(&mint[0][0][0][0],&mint[m-1][n-1][4][101]+1,false);
    mint[sh][sw][0][0] = true;;
    queue<P2> q;
    q.push(P2(P1(0,0),P1(sh,sw)));
    int ans = 1<<30;

    while(q.size()){
      P2 p=q.front();q.pop();
      int t = p.first.first;
      int d = p.first.second;
      int y = p.second.first;
      int x = p.second.second;

      for(int dd=0;dd<4;dd++){
	if(dd==(d+2)%4)continue;
	int dy=y,dx=x,dt=t;
	if(dd==0)dx++;
	if(dd==1)dy++;
	if(dd==2)dx--;
	if(dd==3)dy--;
	if(dy<0 || dx<0 || m<=dy || n<=dx)continue;
	if(cost[y][x][dy][dx]<0)continue;
	dt += cost[y][x][dy][dx];
	k = sig[dy][dx];
	if(k && ( ((dt/k)&1) == (dd&1) ) )continue;
	if(!mint[dy][dx][dd][dt]){
	  if(dy==gh && dx==gw)ans = min(ans,dt);
	  mint[dy][dx][dd][dt] = true;;
	  q.push(P2(P1(dt,dd),P1(dy,dx)));
	}
      }
    }
    cout << ans << endl;
  }
}