bool debug=false;
#include <stdio.h>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
typedef pair<double,double> pd;
typedef pair<pd,double> ppdd;
typedef pair<pd,pd> ppdpd;
#define F first
#define S second
#define PB push_back
const double N=0.00005;
const double eps=1e-9;
double dist(pd a,pd b){
	double x=a.F-b.F,y=a.S-b.S;
	return sqrt(x*x+y*y);
}
double myabs(double n){return n>=0?n:-n;}
int pn(double n){return myabs(n)<eps?0:n>0?1:-1;}
bool between(pd a,pd b,pd c){
	if((-eps<=b.F-a.F&&-eps<=c.F-b.F)||(a.F-b.F>=-eps&&b.F-c.F>=-eps))if((-eps<=b.S-a.S&&-eps<=c.S-b.S)||(a.S-b.S>=-eps&&b.S-c.S>=-eps))return true;
	return false;
}
bool intersect(pd x1,pd x2,pd y1,pd y2){
	if(debug)printf("x1=(%.3lf,%.3lf) x2=(%.3lf,%.3lf) y1=(%.3lf,%.3lf) y2=(%.3lf,%.3lf)\n",x1.F,x1.S,x2.F,x2.S,y1.F,y1.S,y2.F,y2.S); 
	double A1=x1.S-x2.S,B1=x2.F-x1.F,A2=y1.S-y2.S,B2=y2.F-y1.F,C1,C2;
	C1=A1*x1.F+B1*x1.S;
	C2=A2*y1.F+B2*y1.S;
	if(myabs(A1*B2-A2*B1)<eps){
		if(myabs(A2*x1.F+B2*x1.S-C2)<eps)return between(x1,y1,x2)|between(y1,x1,y2);
		else return false;
	}
	else{
		double x=(C1*B2-C2*B1),y=(A1*C2-C1*A2),det=(A1*B2-A2*B1);
		pd p={x/det,y/det};
		return between(x1,p,x2)&between(y1,p,y2);
	}
}
bool cansee(double range,vector<ppdpd> &v,ppdd a0,ppdd a1,ppdd b0,ppdd b1,double now){
	pd apos={(a1.F.F-a0.F.F)*(now-a0.S)/(a1.S-a0.S)+a0.F.F,(a1.F.S-a0.F.S)*(now-a0.S)/(a1.S-a0.S)+a0.F.S},bpos={(b1.F.F-b0.F.F)*(now-b0.S)/(b1.S-b0.S)+b0.F.F,(b1.F.S-b0.F.S)*(now-b0.S)/(b1.S-b0.S)+b0.F.S};
	if(debug)printf("apos=(%.3lf,%.3lf) bpos=(%.3lf,%.3lf)\n",apos.F,apos.S,bpos.F,bpos.S);
	if(dist(apos,bpos)>range){
		if(debug)printf("too far\n");
		return false;
	}
	for(ppdpd i:v)if(intersect(i.F,i.S,apos,bpos)){
		if(debug)printf("intersect\n");
		return false;
	}
	b1.F={(b1.F.F-b0.F.F)+bpos.F,(b1.F.S-b0.F.S)+bpos.S};
	double Al,Bl,Cl,Ar,Br,Cr,A=b0.F.S-b1.F.S,B=b1.F.F-b0.F.F,C,rA,rB,rC;
	int l,r;
	pd lpos,rpos;
	C=A*b0.F.F+B*b0.F.S;
	rA=B;
	rB=-A;
	rC=rA*b1.F.F+rB*b1.F.S;
	lpos={b1.F.F+bpos.S-b1.F.S,b1.F.S+b1.F.F-bpos.F};
	rpos={b1.F.F-bpos.S+b1.F.S,b1.F.S-b1.F.F+bpos.F};
	Al=lpos.S-bpos.S,Ar=rpos.S-bpos.S;
	Bl=bpos.F-lpos.F,Br=bpos.F-rpos.F;
	Cl=Al*bpos.F+Bl*bpos.S;
	Cr=Ar*bpos.F+Br*bpos.S;
	l=pn(Al*apos.F+Bl*apos.S-Cl);
	r=pn(Ar*apos.F+Br*apos.S-Cr);
	if(l==0||l==pn(Al*b1.F.F+Bl*b1.F.S-Cl))if(r==0||r==pn(Ar*b1.F.F+Br*b1.F.S-Cr)){
		if(debug)printf("ok::l=%d ansl=%d r=%d ansr=%d\n",l,pn(Al*b1.F.F+Bl*b1.F.S-Cl),r,pn(Ar*b1.F.F+Br*b1.F.S-Cr));
		return true;
	}
	if(debug)printf("no::l=%d ansl=%d r=%d ansr=%d\n",l,pn(Al*b1.F.F+Bl*b1.F.S-Cl),r,pn(Ar*b1.F.F+Br*b1.F.S-Cr));
	return false;
}
void solve(double t,double r){
	int l,m,n,lpos=0,rpos=0;
	double ans=0,now=N,last=0;
	ppdd temp;
	ppdpd tt;
	vector<ppdd> a,b;
	vector<ppdpd> wall;
	scanf("%d",&l);
	for(int i=0;i<l;i++){
		scanf("%lf%lf%lf",&temp.F.F,&temp.F.S,&temp.S);
		a.PB(temp);
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%lf%lf%lf",&temp.F.F,&temp.F.S,&temp.S);
		b.PB(temp);
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf%lf%lf%lf",&tt.F.F,&tt.F.S,&tt.S.F,&tt.S.S);
		wall.PB({{tt.F.F,tt.F.S},{tt.F.F,tt.S.S}});
		wall.PB({{tt.F.F,tt.S.S},{tt.S.F,tt.S.S}});
		wall.PB({{tt.F.F,tt.F.S},{tt.S.F,tt.F.S}});
		wall.PB({{tt.S.F,tt.F.S},{tt.S.F,tt.S.S}});
	}
	while(now<t){
		while(lpos+2<l&&a[lpos+1].S<now)lpos++;
		while(rpos+2<m&&b[rpos+1].S<now)rpos++;
		if(!cansee(r,wall,a[lpos],a[lpos+1],b[rpos],b[rpos+1],now)){
			ans+=now-last-N;
			if(debug)printf("last=%lf now=%lf ans=%lf\n",last,now,ans);
			last=now;
		}
		now+=N;
	}
	ans+=now-last-N;
	printf("%.20lf\n",(double)ans);
}
int main(){
	int t,r,cnt=0;
	while(true){
		scanf("%d%d",&t,&r);
		if(t==0&&r==0)return 0;
		solve(t,r);
	}
}



Measured memory_bytes: 2732