/*
 * First idea:
 * Calculate possible points, where you might want to change directions.
 * These are the starting point, the ending point and the intersection(s) of two circles with radius D.
 * Do Dijkstra (on the fly calculate which edges are allowed)
 * Complexity: O(n^2+n^5log(n)+n^2log(n))
 * +- 60 min
 */
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;

#define MP make_pair
#define SZ(v) ((int)(v).size())
#define PB push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPSZ(i,v) REP(i,SZ(v))
#define VAR(a,b) __typeof(b) a=b
#define FORIT(i,v) for(VAR(i,(v).begin());i!=(v).end();++i)
const double eps=1e-9;

typedef pair<int,int> PII;
typedef vector<PII> VPII;

typedef struct P { double x,y; P(double x,double y):x(x),y(y) {} P() {} } P;
P operator-(const P &a,const P &b) { return P(a.x-b.x,a.y-b.y); }
P operator+(const P &a,const P &b) { return P(a.x+b.x,a.y+b.y); }
double operator*(const P &a,const P &b) { return a.x*b.x+a.y*b.y; }
double len(const P &a) { return sqrt(a*a); }
P operator*(const double &a,const P &b) { return P(a*b.x,a*b.y); }


P normal(const P &a) { return P(-a.y,a.x); }
bool circlecircle(P p1,double r1,P p2,double r2,P &ret1,P &ret2) {
	double d=len(p2-p1);
	if(d>r1+r2||d<fabs(r1-r2)) return false;
	
	double a=(r1*r1-r2*r2+d*d)/(2*d);
	double h=sqrt(r1*r1-a*a);
	P p3=p1+(a/d)*(p2-p1);
	
	ret1=p3+h/d*normal(p2-p1);
	ret2=p3-h/d*normal(p2-p1);
	return true;
}
bool linecircle(P p1,P p2,P p3,double r,double &u1,double &u2) {
	double a=(p2-p1)*(p2-p1);
	double b=(p2-p1)*(p1-p3)*2;
	double c=(p3-p1)*(p3-p1)-r*r;
	double d=b*b-4*a*c;
	if(d<0) return false;
	
	u1=(-b-sqrt(d))/(2*a);
	u2=(-b+sqrt(d))/(2*a);
	return true;
}

int ntowers,r;
int sx,sy,ex,ey;
int x[100],y[100];


P p[2+100*101]; int n;
//vector<pair<int,double> > adj[2+50*51];

double best[2+100*101];

#define ADD(node,cost) { best[node]=cost; q.push(MP(-(cost),node)); }

bool can(int i,int j) {
	vector<pair<double,int> > order;
	double a,b;
	REP(k,ntowers) if(linecircle(p[i],p[j],P(x[k],y[k]),r,a,b)) {
		if(a>b) swap(a,b);
		if(a<0) a=0;
		if(b>1) b=1;
		if(a+eps>=b) continue;
		order.PB(MP(a-eps,+1));
		order.PB(MP(b+eps,-1));
	}
	sort(order.begin(),order.end());
//	printf("%d %d: ",i,j); REPSZ(k,order) printf("(%lf,%d)",order[k].first,order[k].second); puts("");
	if(SZ(order)==0) return false;
	if(order[0].first>0) return false;
	if(order.back().first<1) return false;
	int cnt=0;
	REPSZ(k,order) {
		if(k!=0&&cnt<=0) return false;
		cnt+=order[k].second;
	}
	return true;
}

void run() {
	scanf("%d%d",&r,&ntowers);
	scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
	REP(i,ntowers) scanf("%d%d",&x[i],&y[i]);
	
	n=0;
	p[n++]=P(sx,sy);
	p[n++]=P(ex,ey);
	REP(i,ntowers) FOR(j,i+1,ntowers) {
		P a,b;
		if(circlecircle(P(x[i],y[i]),r,P(x[j],y[j]),r,a,b)) {
			p[n++]=a;
			p[n++]=b;
		}
	}
	
//	REP(i,n) printf("%d: (%lf,%lf)\n",i,p[i].x,p[i].y);
	
	REP(i,n) best[i]=1e200;
	priority_queue<pair<double,int> > q;
	ADD(0,0);
	while(!q.empty()) {
		int i=q.top().second; double dist=-q.top().first; q.pop();
		if(i==1) { printf("%.9lf\n",dist); return; }
		if(dist>best[i]) continue;
//		printf("%d=%lf\n",i,dist);
		REP(j,n) {
			double ndist=dist+len(p[j]-p[i]);
			if(ndist<best[j]&&can(i,j)) ADD(j,ndist);
		}
	}
	printf("-1\n");
}

int main() {
	int n; scanf("%d",&n); REP(i,n) run();
	
	return 0;
}
