#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
#define Y1 b1[0]-'a'
#define X1 b1[2]-'1'
#define Y2 b2[0]-'a'
#define X2 b2[2]-'1'
#define INF (1<<20)
using namespace std;
int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
int m,n,ds,ns,nc,nj,sy,sx,gy,gx,t,
S[20][20],D[20][20][20][20]; bool V[20][20][101][4]; char ch,tmp;
void dfs(int y,int x,int t,int d){
	V[y][x][t][d]=1;
	int ny,nx,c,nt,nd;
	rep(i,4){
		nd=d+i&3,ny=y+dy[nd],nx=x+dx[nd];
		if(ck(ny,m)&&ck(nx,n)&&i!=2){
			c=D[y][x][ny][nx],nt=t+c;
			if((!S[ny][nx]||nd%2==nt/S[ny][nx]%2)&&c!=INF
			&&nt<101&&!V[ny][nx][nt][nd])dfs(ny,nx,nt,nd);
		}
	}
}
int main(){
	while(cin>>m>>n,m){
		cin>>ds; rep(y,m)rep(x,n){
			S[y][x]=0; rep(d,4){
				int ny=y+dy[d],nx=x+dx[d];
				if(ck(ny,m)&&ck(nx,n))D[y][x][ny][nx]=D[ny][nx][y][x]=ds;
			}
		}
		int x1,x2,y1,y2,k;
		cin>>ns; rep(i,ns){
			cin>>ch>>tmp>>x1>>k; x1--;
			S[ch-'a'][x1]=k;
		}
		cin>>nc; rep(i,nc){
			cin>>ch>>tmp>>x1; y1=ch-'a'; x1--;
			cin>>ch>>tmp>>x2; y2=ch-'a'; x2--;
			D[y1][x1][y2][x2]=D[y2][x2][y1][x1]=INF;
		}
		cin>>nj; rep(i,nj){
			cin>>ch>>tmp>>x1; y1=ch-'a'; x1--;
			cin>>ch>>tmp>>x2>>k; y2=ch-'a'; x2--;
			D[y1][x1][y2][x2]+=k,D[y2][x2][y1][x1]+=k;
		}
		cin>>ch>>tmp>>sx; sy=ch-'a'; sx--;
		cin>>ch>>tmp>>gx; gy=ch-'a'; gx--;
		
		rep(i,m)rep(j,n)rep(t,101)rep(d,4)V[i][j][t][d]=0;
		rep(d,4)dfs(sy,sx,0,d);
		rep(t,101)rep(d,4)if(V[gy][gx][t][d]){
			cout<<t<<endl; goto END;
		}
		END:;
	}
	return 0;
}