#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
using ll = long long;

const int inf = 1e9;

pair<int,int> convert(string s){
    return { s[0]-'a', atoi(&s[2])-1 };
}

int h,w;
int sign[20][20];
int sig[20][20][4];
int c[20][20][4];
int vis[20][20][4][101];

int main() {
    while(cin >> h >> w && h){
        const int dy[] = {-1, 0, 1, 0};
        const int dx[] = {0, -1, 0, 1};
        int d, ns;
        cin >> d >> ns;
        memset(sign, 0, sizeof(sign));
        memset(sig, 0, sizeof(sig));
        memset(c, 0, sizeof(c));
        memset(vis, 0, sizeof(vis));
        rep(i, ns){
            string s;
            int k;
            cin >> s >> k;
            int y,x;
            tie(y,x) = convert(s);
            sign[y][x] = k;
        }
        int nc;
        cin >> nc;
        rep(i,nc){
            string s1, s2;
            cin >> s1 >> s2;
            int x1, x2, y1, y2;
            tie(y1,x1) = convert(s1);
            tie(y2,x2) = convert(s2);
            rep(j,4){
                if(y1+dy[j] == y2 && x1+dx[j] == x2){
                    sig[y1][x1][j] = true;
                    sig[y2][x2][(j+2)%2] = true;
                    break;
                }
            }
        }

        int nj;
        cin >> nj;
        rep(i, nj){
            string s1, s2;
            int d;
            cin >> s1 >> s2 >> d;
            int x1, y1, x2, y2;
            tie(y1,x1) = convert(s1);
            tie(y2,x2) = convert(s2);
            rep(j,4){
                if(y1+dy[j] == y2 && x1+dx[j] == x2){
                    c[y1][x1][j] = d;
                    c[y2][x2][(j+2)%2] = d;
                    break;
                }
            }
        }

        string s, g;
        cin >> s >> g;
        int ys,xs,yg,xg;
        tie(ys,xs) = convert(s);
        tie(yg,xg) = convert(g);
        int ans = -1;
        using State = tuple<int,int,int,int>;
        priority_queue<State> q;
        q.emplace(0, ys, xs, 3);
        while(q.size()){
            int ct,cy,cx,cd;
            tie(ct,cy,cx,cd) = q.top(); q.pop();
            ct *= -1;
            if(vis[cy][cx][cd][ct]) continue;
            vis[cy][cx][cd][ct] = true;
            if(cy == yg && cx == xg){
                ans = ct;
                break;
            }
            rep(i,4){
                if(abs(cd-i) == 2 || sig[cy][cx][i]) continue;
                int ny = cy + dy[i];
                int nx = cx + dx[i];
                if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
                int nt = ct + d + c[cy][cx][i];
                if(sign[ny][nx] == 0 || (((nt/sign[ny][nx])%2) ^ (i%2==0))){
                    q.emplace(-nt, ny, nx, i);
                }
            }
        }
        cout << ans << endl;
    }
}