/*
几何
求给定三角形的外接圆圆心
方法:求解二元方程组
*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
const double pi = acos(-1.0);
const double eps = 1e-;
struct Point{
double x,y;
};
struct Circle{
Point center;
double r;
};
Point a,b,c,tp;
Circle cc;
double dis( Point a,Point b ){
return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) );
}
bool JudgeTriangle( Point a,Point b,Point c ){
double len1 = dis( a,b );
len1 *= len1;
double len2 = dis( a,c );
len2 *= len2;
double len3 = dis( b,c );
len3 *= len3;
if( len1+len2-len3<=||len1+len3-len2<=||len2+len3-len1<= ) return false;
else return true;
}/*判断是否是钝角三角形*/
void GetCircle( Point a,Point b,Point c ){
bool judge = JudgeTriangle( a,b,c );
if( judge==false ){
double ans;
int op ;
double len1 = dis( a,b );
ans = len1;
op = ;
double len2 = dis( a,c );
if( len2>ans ){
ans = len2;
op = ;
}
double len3 = dis( b,c );
if( len3>ans ){
ans = len3;
op = ;
}
cc.r = ans / 2.0;
if( op== ){
cc.center.x = ( a.x+b.x )/2.0;
cc.center.y = ( a.y+b.y )/2.0;
}
else if( op== ){
cc.center.x = ( a.x+c.x )/2.0;
cc.center.y = ( a.y+c.y )/2.0;
}
else {
cc.center.x = ( b.x+c.x )/2.0;
cc.center.y = ( b.y+c.y )/2.0;
}
return ;
}/*钝角三角形*/
double x1 = a.x,x2 = b.x,x3 = c.x;
double y1 = a.y,y2 = b.y,y3 = c.y;
cc.center.x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(*(x3-x1)*(y2-y1)-*((x2-x1)*(y3-y1)));
cc.center.y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(*(y3-y1)*(x2-x1)-*((y2-y1)*(x3-x1)));
cc.r = dis( cc.center,a );
return ;
}/*求外接圆圆心*/
int main(){
int T;
scanf("%d",&T);
int ca = ;
while( T-- ){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&tp.x,&tp.y);
GetCircle( a,b,c );
printf("Case #%d: ",ca++);
if( dis( tp,cc.center )<=cc.r ) printf("Danger\n");
else printf("Safe\n");
}
return ;
}