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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

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

int H,W,D;
int T[20][20];
int G[20][20][20][20];

inline void get(int &y,int &x){
    char c;
    scanf(" %c-%lld",&c,&x);
    x--;y=c-'a';
}

bool visited[20][20][111][4];


void solve(){
    cin>>D;
    memset(T,-1,sizeof(T));
    int n;cin>>n;
    while(n--){
        int y,x;
        get(y,x);
        int t;scanf("%lld",&t);
        T[y][x]=t;
    }
    fill_n(***G,20*20*20*20,D);
    cin>>n;
    while(n--){
        int y,x,yy,xx;
        get(y,x);get(yy,xx);
        G[y][x][yy][xx]=G[yy][xx][y][x]=INF;
    }
    cin>>n;
    while(n--){
        int y,yy,x,xx,t;
        get(y,x);get(yy,xx);scanf("%lld",&t);
        G[y][x][yy][xx]=G[yy][xx][y][x]=D+t;
    }

    int sy,sx,gy,gx;
    get(sy,sx);get(gy,gx);

    memset(visited,0,sizeof(visited));
    visited[sy][sx][0][1]=true;
    queue<tuple<int,int,int,int>>que;
    que.push(make_tuple(sy,sx,0,1));
    while(que.size()){
        int y,x,t,pre_d;
        tie(y,x,t,pre_d)=que.front();
        que.pop();

        rep(d,4){
            if((d+2)%4==pre_d)continue;
            int ny=y+dy[d],nx=x+dx[d];
            if(ny<0||ny>=H||nx<0||nx>=W)continue;
            int nt=t+G[y][x][ny][nx];
            if(nt>100)continue;
            if(T[ny][nx]!=-1&&(nt%(2*T[ny][nx])>=T[ny][nx])!=d%2)continue;
            if(visited[ny][nx][nt][d])continue;
            visited[ny][nx][nt][d]=true;
            que.push(make_tuple(ny,nx,nt,d));
        }
    }

    rep(t,101)rep(d,4)if(visited[gy][gx][t][d]){
        cout<<t<<endl;
        return;
    }

    /*
    rep(i,H){rep(j,W){
        int a=101;
        rep(t,101)rep(d,4)if(visited[i][j][t][d])chmin(a,t);
        if(a==101)cout<<-1<<" ";
        else cout<<a<<" ";
    }cout<<endl;}
    */
}

signed main(){
    while(cin>>H>>W,W||H)solve();
    return 0;
}