#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
struct point{double x, y;}p[5];
double dist(point a, point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
bool ok(point midp, double r, point pp)
{
if((pp.x-midp.x)*(pp.x-midp.x) + (pp.y-midp.y)*(pp.y-midp.y) <= r*r) return true;
return false;
}
int main()
{
int t, kase = 0;
scanf("%d", &t);
while(t--)
{
for(int i = 1; i <= 4; ++i)
scanf("%lf%lf", &p[i].x, &p[i].y);
int left, right, ll, rr, len = 0;
double dis[3];
for(int i = 1; i <= 2; ++i)
for(int j = i+1; j <= 3; ++j)
dis[len++] = dist(p[i], p[j]);
point midp;
double r;
double maxdis = max(dis[0], max(dis[1], dis[2]));
if(dis[0] == maxdis) {left = 1; right = 2; ll = 1; rr = 2;}
else if(dis[1] == maxdis) {left = 0; right = 2; ll = 1; rr = 3;}
else {left = 0; right = 1; ll = 2; rr = 3;}
if(maxdis*maxdis > dis[left]*dis[left] + dis[right]*dis[right])
{
r = maxdis/2;
midp.x = (p[ll].x+p[rr].x)/2;
midp.y = (p[ll].y+p[rr].y)/2;
}
else
{
double L = (dis[0]+dis[1]+dis[2])/2;
double S = sqrt((L*(L-dis[0])*(L-dis[1])*(L-dis[2])));
r = dis[0]*dis[1]*dis[2]/(4*S);
midp.x = ((p[1].x*p[1].x+p[1].y*p[1].y-p[2].x*p[2].x-p[2].y*p[2].y)*(p[1].y-p[3].y)-(p[1].x*p[1].x+p[1].y*p[1].y-p[3].x*p[3].x-p[3].y*p[3].y)*(p[1].y-p[2].y))/(2.0*((p[1].y-p[3].y)*(p[1].x-p[2].x)-(p[1].y-p[2].y)*(p[1].x-p[3].x)));
midp.y = ((p[1].x*p[1].x+p[1].y*p[1].y-p[2].x*p[2].x-p[2].y*p[2].y)*(p[1].x-p[3].x)-(p[1].x*p[1].x+p[1].y*p[1].y-p[3].x*p[3].x-p[3].y*p[3].y)*(p[1].x-p[2].x))/(2.0*((p[1].x-p[3].x)*(p[1].y-p[2].y)-(p[1].x-p[2].x)*(p[1].y-p[3].y)));
}
printf("Case #%d: ", ++kase);
if(ok(midp, r, p[4])) puts("Danger");
else puts("Safe");
}
return 0;
}
midp.x = ((p[1].x*p[1].x+p[1].y*p[1].y-p[2].x*p[2].x-p[2].y*p[2].y)*(p[1].y-p[3].y)-(p[1].x*p[1].x+p[1].y*p[1].y-p[3].x*p[3].x-p[3].y*p[3].y)*(p[1].y-p[2].y))/(2.0*((p[1].y-p[3].y)*(p[1].x-p[2].x)-(p[1].y-p[2].y)*(p[1].x-p[3].x)));//圆心坐标X
midp.y = ((p[1].x*p[1].x+p[1].y*p[1].y-p[2].x*p[2].x-p[2].y*p[2].y)*(p[1].x-p[3].x)-(p[1].x*p[1].x+p[1].y*p[1].y-p[3].x*p[3].x-p[3].y*p[3].y)*(p[1].x-p[2].x))/(2.0*((p[1].x-p[3].x)*(p[1].y-p[2].y)-(p[1].x-p[2].x)*(p[1].y-p[3].y)));//圆心坐标Y
L = (dis[0]+dis[1]+dis[2])/2;
S = sqrt((L*(L-dis[0])*(L-dis[1])*(L-dis[2])));//海伦公式
r = dis[0]*dis[1]*dis[2]/(4*S);//外接圆半径