Problem: You are given two solid polygons and their positions on the xy-plane. You can move one of the two along the x-axis (they can overlap during the move). You cannot move it in other directions. The goal is to place them as compactly as possible, subject to the following condition: the distance between any point in one polygon and any point in the other must not be smaller than a given minimum distance L.

We define the width of a placement as the difference between the maximum and the minimum x-coordinates of all points in the two polygons.

Your job is to write a program to calculate the minimum width of placements satisfying the above condition.

Let's see an example. If the polygons in Figure 13 are placed with L = 10.0, the result will be 100. Figure 14 shows one of the optimal placements.

<image>



Input

The input consists of multiple datasets. Each dataset is given in the following format.


L
Polygon1
Polygon2


<image>

L is a decimal fraction, which means the required distance of two polygons. L is greater than 0.1 and less than 50.0.

The format of each polygon is as follows.


n
x1 y1
x2 y2
.
.
.
xn yn


n is a positive integer, which represents the number of vertices of the polygon. n is greater than 2 and less than 15.

Remaining lines represent the vertices of the polygon. A vertex data line has a pair of nonneg- ative integers which represent the x- and y-coordinates of a vertex. x- and y-coordinates are separated by a single space, and y-coordinate is immediately followed by a newline. x and y are less than 500.

Edges of the polygon connect vertices given in two adjacent vertex data lines, and vertices given in the last and the first vertex data lines. You may assume that the vertices are given in the counterclockwise order, and the contours of polygons are simple, i.e. they do not cross nor touch themselves.

Also, you may assume that the result is not sensitive to errors. In concrete terms, for a given pair of polygons, the minimum width is a function of the given minimum distance l. Let us denote the function w(l). Then you can assume that |w(L ± 10-7) - w(L)| < 10-4.

The end of the input is indicated by a line that only contains a zero. It is not a part of a dataset.

Output

The output should consist of a series of lines each containing a single decimal fraction. Each number should indicate the minimum width for the corresponding dataset. The answer should not have an error greater than 0.0001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.

Example

Input

10.5235
3
0 0
100 100
0 100
4
0 50
20 50
20 80
0 80
10.0
4
120 45
140 35
140 65
120 55
8
0 0
100 0
100 100
0 100
0 55
80 90
80 10
0 45
10.0
3
0 0
1 0
0 1
3
0 100
1 101
0 101
10.0
3
0 0
1 0
0 100
3
0 50
100 50
0 51
0


Output

114.882476
100
1
110.5005

Solution (in CPP):

Solution:
/*
 *   Created By phyxnj@uestc
 *   Last Compiler:
 *   Sun, 29 Jul 2012 02:07:44 +0800
 */
#include <cstdio>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <iostream>
using namespace std;
#define eps 1e-7
#define pw(x) ((x)*(x))
typedef long long LL;
struct P
{
    double x,y;
    P () {}
    P (double x,double y) : x(x),y(y) {}
    P operator - (const P & b)
    {
        return P (x-b.x,y-b.y);
    }
    double operator * (const P & b)
    {
        return x*b.y-y*b.x;
    }
    double operator & (const P & b)
    {
        return x*b.x+y*b.y;
    }
    double dorm()
    {
        return sqrt(pw(x)+pw(y));
    }
}p[300],s[300],tp[300];
int sgn(double x)
{
    return x<-eps?-1:x>eps;
}
double cal(P a,P b,P c) // 隶。邂幼蛻ーab逧?怙蟆剰キ晉ヲサ
{
    int t1=sgn((c-a)&(b-a));
    int t2=sgn((c-b)&(a-b));
    if(t1>=0&&t2>=0) return fabs((a-c)*(a-b))/(a-b).dorm();
    return min((c-a).dorm(),(c-b).dorm());
}
double maybe[10000]; 
int cnt,flag;
double L;
int n,m;
void run(P a,P b,P c) // 隶。邂苓ヲ∽スソ蠕幼荳斬b逧?怙蟆剰キ晉ヲサ荳コL隕∽スソc遘サ蜉ィ逧?キ晉ヲサ
{
    double l=-20000,h=20000,mid1,mid2;
    for(int i=0;i<50;i++){
        mid1=(2*l+h)/3;
        mid2=(2*h+l)/3;
        double t1=cal(a,b,P(mid1,c.y));
        double t2=cal(a,b,P(mid2,c.y));
        if(sgn(t1-t2)>=0) l=mid1;
        else h=mid2;
    }
    double mid;
    l=-20000;h=mid1;
    for(int i=0;i<50;i++){
        mid=(l+h)/2;
        double t1=cal(a,b,P(mid,c.y));
        if(sgn(t1-L)>=0) l=mid;
        else h=mid;
    }
    double delta=mid-c.x;
    if(flag) delta=-delta;
    maybe[cnt++]=delta;
    l=mid1,h=20000;
    for(int i=0;i<50;i++){
        mid=(l+h)/2;
        double t1=cal(a,b,P(mid,c.y));
        if(sgn(t1-L)>=0) h=mid;
        else l=mid;
    }
    delta=mid-c.x;
    if(flag) delta=-delta;
    maybe[cnt++]=delta;
}
void creat()
{
    cnt=0;
    s[m]=s[0],p[n]=p[0];
    flag=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            run(s[j],s[j+1],p[i]);
        }
    }
    flag=0;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            run(p[j],p[j+1],s[i]);
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++) {
            maybe[cnt++]=p[j].x-s[i].x;
        }
    }
}
int in(P a,P pt[],int n)
{
    int cnt=0;
    pt[n]=pt[0];
    for(int i=0;i<n;i++){
        P x=pt[i],y=pt[i+1];
        if(sgn(x.y-y.y)>0) swap(x,y);
        if(sgn(x.y-a.y)>=0||sgn(y.y-a.y)<0) continue;
        double t=(x-a)*(y-a);
        if(sgn(t)>0) cnt++;
    }
    return cnt&1;
}
double solve()
{
    double ans=1e10;
    for(int i=0;i<cnt;i++){
        double x=maybe[i];
//        printf("%f\n",x);
        for(int j=0;j<m;j++){
            tp[j].x=s[j].x+x;
            tp[j].y=s[j].y;
        }
        tp[m]=tp[0];
        int flag=0;
        for(int j=0;j<n;j++){
            for(int k=0;k<m;k++){
                int t1=sgn((p[j]-tp[k])*(tp[k+1]-tp[k]))*sgn((p[j+1]-tp[k])*(tp[k+1]-tp[k]));
                int t2=sgn((tp[k]-p[j])*(p[j+1]-p[j]))*sgn((tp[k+1]-p[j])*(p[j+1]-p[j]));
                if(t1<0&&t2<0) {
                    flag=1;
                    break;
                }
                double dis=min(min(cal(p[j],p[j+1],tp[k]),cal(p[j],p[j+1],tp[k+1])),min(cal(tp[k],tp[k+1],p[j]),cal(tp[k],tp[k+1],p[j+1])));
                if(dis-L<-1e-6) {
                    flag=1;
                    break;
                }
            }
        }
        if(flag) continue;
        flag=in(tp[0],p,n)||in(p[0],tp,m);
        if(flag) continue;
        double minx=1e10,maxx=-1e10;
        for(int j=0;j<m;j++){
            minx=min(minx,tp[j].x);
            maxx=max(maxx,tp[j].x);
        }
        for(int j=0;j<n;j++){
            minx=min(minx,p[j].x);
            maxx=max(maxx,p[j].x);
        }
//        printf("%f %f ************\n",maxx,minx);
        ans=min(ans,maxx-minx);
    }
    return ans;
}
int main()
{   
    P a,b,c;
    while(scanf("%lf",&L)&&sgn(L)){
        scanf("%d",&n);
        for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
        scanf("%d",&m);
        for(int i=0;i<m;i++) scanf("%lf%lf",&s[i].x,&s[i].y);
        creat();
        printf("%f\n",solve());
    }
    return 0;
}