#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 110
int queue[MAX*100];
int c[MAX][MAX];
int flow[MAX][MAX];
int pre[MAX+10];
bool visit[MAX];
int n;
bool adjust(int u,int s)
{
int j;
int front=0,rear=0;
memset(visit,false,sizeof(visit));
for(j=0;j<=n+1;j++)
pre[j]=-1;
visit[u]=true;
queue[rear++]=u;
while(front<rear)
{
u=queue[front++];
for(j=1;j<=n+2;j++)
{
if(!visit[j] && c[u][j]>flow[u][j])
{
visit[j]=true;
pre[j]=u;
queue[rear++]=j;
if(j==s)
return true;
}
}
}
return false;
}
int Maxflow(int u,int s)
{
int i,j;
int maxflow=0,min=INT_MAX;
j=s;
while(j!=u)
{
i=pre[j];
if((c[i][j]-flow[i][j])<min)
min=c[i][j]-flow[i][j];
j=i;
}
j=s;
while(j!=u)
{
i=pre[j];
flow[i][j]+=min;
flow[j][i]-=min;
j=i;
}
return min;
}
int main()
{
int np,nc,m,i,j;
int u,v,z;
int max;
char ch;
while(scanf("%d%d%d%d",&n,&np,&nc,&m)!=EOF)
{
getchar();
max=0;
memset(c,0,sizeof(c));
memset(flow,0,sizeof(flow));
for(i=0;i<m;i++)
{
while(scanf("%c",&ch) && ch!='(');
scanf("%d,%d)%d",&u,&v,&z);
c[u+1][v+1]=z;
}
for(i=0;i<np;i++)
{
while(scanf("%c",&ch) && ch!='(');
scanf("%d)%d",&u,&z);
c[n+1][u+1]=z;
}
for(i=0;i<nc;i++)
{
while(scanf("%c",&ch) && ch!='(');
scanf("%d)%d",&u,&z);
c[u+1][n+2]=z;
}
while(adjust(n+1,n+2))
max+=Maxflow(n+1,n+2);
printf("%d/n",max);
}
return 0;
}