#include <bits/stdc++.h>
using namespace std;

const int INF = 1 << 28;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

struct State {
	int x, y, cost;
	State(int x = 0, int y = 0, int cost = 0): x(x), y(y), cost(cost){}
	bool operator < (const State &t) const {
		return cost > t.cost;
	}
};

int m, n;
int D;

int sign[20][20];
int cost[20][20][20][20];
int dist[20][20];

bool ok(int x, int y)
{
	return x >= 0 && x < m && y >= 0 && y < n;
}

int calc(int x, int y, int nx, int ny)
{
	return D + cost[x][y][nx][ny];
}

void solve(int x1, int y1, int x2, int y2)
{
	fill_n((int*)dist, 20 * 20, INF);
	priority_queue<State> que;
	que.push(State(x1, y1, 0));
	
	bool done_first = false;
	
	while (que.size()){
		State st = que.top(); que.pop();
		if (dist[st.x][st.y] < st.cost) continue;
		dist[st.x][st.y] = st.cost;
		for (int dir = 0; dir < 4; dir++){
			if (!done_first && dir == 0) continue;
			
			int nx = st.x + dx[dir];
			int ny = st.y + dy[dir];
			if (!ok(nx, ny)) continue;
			int nc = st.cost + calc(st.x, st.y, nx, ny);
			if (sign[nx][ny]){
				if ((dir ^ (nc / sign[nx][ny])) & 1){
					nc = INF;
				}
			}
			if (dist[nx][ny] > nc){
				dist[nx][ny] = nc;
				que.push(State(nx, ny, nc));
			}
		}
		
		done_first = true;
	}
	
	printf("%d\n", dist[x2][y2]);
}

int main()
{
	while (scanf("%d %d", &m, &n), m){
		memset(sign, 0, sizeof(sign));
		memset(cost, 0, sizeof(cost));
		
		scanf("%d", &D);
		
		int ns;
		scanf("%d", &ns);
		for (int i = 0; i < ns; i++){
			char h;
			int v, k;
			scanf(" %c-%d %d", &h, &v, &k);
			int x = h - 'a';
			int y = v - 1;
			sign[x][y] = k;
		}
		
		int nc;
		scanf("%d", &nc);
		for (int i = 0; i < nc; i++){
			char h1, h2;
			int v1, v2;
			scanf(" %c-%d %c-%d", &h1, &v1, &h2, &v2);
			int x1 = h1 - 'a';
			int y1 = v1 - 1;
			int x2 = h2 - 'a';
			int y2 = v2 - 1;
			cost[x1][y1][x2][y2] += INF;
			cost[x2][y2][x1][y1] += INF;
			
			//if (cost[x1][y1][x2][y2] < 0) assert(false);
		}
		
		int nj;
		scanf("%d", &nj);
		for (int i = 0; i < nj; i++){
			char h1, h2;
			int v1, v2, d;
			scanf(" %c%*c%d %c%*c%d %d", &h1, &v1, &h2, &v2, &d);
			int x1 = h1 - 'a';
			int y1 = v1 - 1;
			int x2 = h2 - 'a';
			int y2 = v2 - 1;
			cost[x1][y1][x2][y2] += d;
			cost[x2][y2][x1][y1] += d;
		}
		
		char h1, h2;
		int v1, v2;
		scanf(" %c%*c%d %c%*c%d", &h1, &v1, &h2, &v2);
		int x1 = h1 - 'a';
		int y1 = v1 - 1;
		int x2 = h2 - 'a';
		int y2 = v2 - 1;
		
		solve(x1, y1, x2, y2);
	}
	
	return 0;
}