#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=50010;
const int mod=1000000007;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const ll MAX=1ll<<55;
const double eps=1e-5;
const double inf=~0u>>1;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
struct node {
ll l,r,p;
}D[N];
ll x[N],f[N];
int cmd(node a,node b) {
return a.r<b.r;
}
void add(int w,ll p) {
for (;w<=N;w+=w&-w) f[w]+=p;
}
ll getsum(int w) {
ll ret=0;
for (;w;w-=w&-w) ret+=f[w];
return ret;
}
int main()
{
int i,g,k,K,num1,num2;
ll a,b,p,n,m,sum,mx,L,R;
while (scanf("%lld%lld", &n, &m)!=EOF) {
scanf("%lld", &L);
R=L+m;g=0;sum=0;
scanf("%d%d", &num1, &num2);
for (i=1;i<=num1;i++) {
scanf("%lld%lld%lld", &a, &b, &p);
if (a+b<L||a+b>R) continue ;
else {
g++;D[g].l=a+2*b;D[g].p=p;sum+=p;
D[g].r=a+2*b+(R-a-b)/(2*b)*(2*b);
}
}
for (i=1;i<=num2;i++) {
scanf("%lld%lld%lld", &a, &b, &p);
g++;D[g].l=a+b;D[g].p=p;sum+=p;
if (R<a+2*b||a+2*b<L) D[g].r=D[g].l;
else D[g].r=a+3*b+(R-a-2*b)/(2*b)*(2*b);
}
for (k=0,i=1;i<=g;i++) {
x[++k]=D[i].l;x[++k]=D[i].r;x[++k]=D[i].r-n;
}
sort(D+1,D+g+1,cmd);
sort(x+1,x+k+1);
K=unique(x+1,x+k+1)-(x+1);
memset(f,0,sizeof(f));mx=0;
for (i=1;i<=g;i++) {
int w,pre,now;
w=lower_bound(x+1,x+K+1,D[i].l)-x;
now=lower_bound(x+1,x+K+1,D[i].r)-x;
pre=lower_bound(x+1,x+K+1,D[i].r-n)-x;
add(w,D[i].p);
mx=max(mx,getsum(now)-getsum(pre-1));
}
printf("%lld\n", sum-mx);
}
return 0;
}