#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#define M 15
#define INF 0x7fffffff/2
using namespace std;
int n,m,k,p,s;
int dp[M][M][1<<M];
int door[M][M][M][M];
int fmap[M][M];
int fx[5]={0,-1,0,1,0};
int fy[5]={0,0,1,0,-1};
struct node
{
int x;
int y;
int key;
int dis;
}str1,str2;
queue <node> q;
bool check(int x1,int y1,int x2,int y2,int key1)
{
int tmp=door[x1][y1][x2][y2];
if(tmp==-1)
return true;
else
{
if(tmp==0)
return false;
else
{
if(key1&(1<<(tmp-1)))
return true;
else
return false;
}
}
}
void bfs()
{
str1.x=1;
str1.y=1;
str1.key=0;
str1.dis=0;
q.push(str1);
while(!q.empty())
{
str1=q.front();
q.pop();
for(int i=1;i<=4;i++)
{
str2.x=str1.x+fx[i];
str2.y=str1.y+fy[i];
if(str2.x>=1&&str2.x<=n&&str2.y>=1&&str2.y<=m&&check(str1.x,str1.y,str2.x,str2.y,str1.key))
{
str2.dis=str1.dis+1;
str2.key=str1.key;
str2.key |= fmap[str2.x][str2.y];
if(str2.dis<dp[str2.x][str2.y][str2.key])
{
dp[str2.x][str2.y][str2.key]=str2.dis;
q.push(str2);
}
}
}
}
}
void init()
{
scanf("%d%d%d",&n,&m,&p);
scanf("%d",&k);
memset(door,-1,sizeof(door));
memset(fmap,0,sizeof(fmap));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
for(int k=0;k<(1<<p);k++)
dp[i][j][k]=INF;
for(int i=1;i<=k;i++)
{
int x1,y1,x2,y2,G;
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&G);
door[x1][y1][x2][y2]=G;
door[x2][y2][x1][y1]=G;
}
scanf("%d",&s);
for(int i=1;i<=s;i++)
{
int x,y,Q;
scanf("%d%d%d",&x,&y,&Q);
fmap[x][y] |= 1<<(Q-1);
}
}
int main()
{
freopen("t14.in","r",stdin);
freopen("t14.out","w",stdout);
init();
bfs();
int ans=INF;
for(int i=0;i<(1<<p);i++)
{
if(ans>dp[n][m][i])
ans=dp[n][m][i];
}
if(ans==INF)
printf("-1\n");
else
printf("%d\n",ans);
return 0;
}