#include<stdio.h> int sx; int sy; int ex; int ey; int map[99][99]; int vist[99]; int N; int sum=0; int min=9999; int juedui(int a,int b) { if(a-b<0) return -1; else return 1; } void chuan(int x,int y) { if(juedui(ex,x)*(ex-x)+juedui(ey,y)*(ey-y)+sum<min) { min=juedui(ex,x)*(ex-x)+juedui(ey,y)*(ey-y)+sum; } for(int i=0;i<N;i++) { if(vist[i]==0) { vist[i]=1; sum=sum+(juedui(x,map[i][0])*(x-map[i][0])+juedui(y,map[i][1])*(y-map[i][1])+map[i][4]); chuan(map[i][2],map[i][3]); sum=sum-(juedui(x,map[i][0])*(x-map[i][0])+juedui(y,map[i][1])*(y-map[i][1])+map[i][4]); sum=sum+(juedui(x,map[i][2])*(x-map[i][2])+juedui(y,map[i][3])*(y-map[i][3])+map[i][4]); chuan(map[i][0],map[i][1]); sum=sum-(juedui(x,map[i][2])*(x-map[i][2])+juedui(y,map[i][3])*(y-map[i][3])+map[i][4]); chuan(x,y); vist[i]=0; } } } int main() { freopen("in.txt","r",stdin); int cass; scanf("%d",&cass); while(cass--) { min=9999; sum=0; scanf("%d",&N); scanf("%d %d %d %d",&sx,&sy,&ex,&ey); for(int i=0;i<N;i++) { vist[i]=0; for(int j=0;j<5;j++) { scanf("%d",&map[i][j]); } } chuan(sx,sy); printf("%d ",min); } return 0; }