Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	x := make([]int, 100)
	y := make([]int, 100)
	r := make([]int, 100)
	for scanner.Scan() {
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		for i := 0; i < a; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmpx, _ := strconv.Atoi(input[0])
			tmpy, _ := strconv.Atoi(input[1])
			tmpr, _ := strconv.Atoi(input[2])
			x[i], y[i], r[i] = tmpx, tmpy, tmpr
		}
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			c, _ := strconv.Atoi(input[0])
			d, _ := strconv.Atoi(input[1])
			e, _ := strconv.Atoi(input[2])
			f, _ := strconv.Atoi(input[3])
			ok := false
			for j := 0; j < a; j++ {
				if (c-x[j])*(c-x[j])+(d-y[j])*(d-y[j]) >= r[j]*r[j] || (e-x[j])*(e-x[j])+(f-y[j])*(f-y[j]) >= r[j]*r[j] {
					if (e-c)*(x[j]-c)+(f-d)*(y[j]-d) < 0 {
						if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d) <= r[j]*r[j] {
							ok = true
						}
					} else {
						if (e-c)*(x[j]-c)+(f-d)*(y[j]-d)>(e-c)*(e-c)+(f-d)*(f-d) {
							if (x[j]-e)*(x[j]-e)+(y[j]-f)*(y[j]-f)<=r[j]*r[j] {
								ok = true
							}
						} else {
							if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d)-((e-c)*(x[j]-c)+(f-d)*(y[j]-d))*((e-c)*(x[j]-c)+(f-d)*(y[j]-d))/((e-c)*(e-c)+(f-d)*(f-d))<=r[j]*r[j] {
								ok = true
							}
						}
					}

				}
			}
			if ok {
				fmt.Println("Safe")
			} else {
				fmt.Println("Danger")
			}
		}
	}
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

typedef complex<double> P;

class circle{
  public:
	int x,y,r;
	circle(int _x, int _y, int _r){
		x=_x; y=_y; r=_r;
	}
};

double dot(P a, P b){
	return a.real()*b.real() + a.imag()*b.imag();
}
double cross(P a, P b){
	return a.real()*b.imag() - a.imag()*b.real();
}

double distance_ls_p(P p0, P p1, P p2){
	if( dot(p1-p0, p2-p0)<-EPS ) return abs(p2-p0);
	if( dot(p0-p1, p2-p1)<-EPS ) return abs(p2-p1);
	return abs(cross(p1-p0,p2-p0))/abs(p1-p0);
}

bool inside(circle& c, int x, int y){
	return (c.x-x)*(c.x-x) + (c.y-y)*(c.y-y) <= c.r*c.r ;
}

int main(){
	int n,m;
	vector<circle> vc;
	
	while(scanf("%d",&n),n){
		vc.clear();
		rep(i,n){
			int a,b,c; scanf("%d%d%d",&a,&b,&c);
			vc.pb( circle(a,b,c) );
		}
		scanf("%d",&m);
		rep(i,m){
			bool f = false;
			int tx,ty,sx,sy; scanf("%d%d%d%d",&tx,&ty,&sx,&sy);
			rep(j,n){
				if(	(inside(vc[j],tx,ty) && !inside(vc[j],sx,sy)) ||
					(!inside(vc[j],tx,ty) && inside(vc[j],sx,sy)) ){
					f = true;
#if DEB
					puts("hoge");
#endif					
					break;
				}else if( !(inside(vc[j],tx,ty) && inside(vc[j],sx,sy)) &&
						  (distance_ls_p(P(tx,ty),P(sx,sy),P(vc[j].x,vc[j].y))<=vc[j].r) ){
					f = true;
#if DEB
					puts("uguu");
#endif					
					break;
				}
			}
			puts(f ? "Safe" : "Danger");
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
const double EPS=1e-10;

double add(double a,double b)
{
	if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}

typedef struct Vec{
	double x,y;
	Vec(){}
	Vec(double x,double y):x(x),y(y){}
	Vec operator +(Vec v){return Vec(add(x,v.x),add(y,v.y));}
	Vec operator -(Vec v){return Vec(add(x,-v.x),add(y,-v.y));}
	Vec operator *(double d){return Vec(x*d,y*d);}
	double dot(Vec v){return add(x*v.x,y*v.y);}
	double det(Vec v){return add(x*v.y,-y*v.x);}
}Vec;

double dot(Vec a,Vec b){return add(a.x*b.x,a.y*b.y);}
double det(Vec a,Vec b){return add(a.x*b.y,-a.y*b.x);}

typedef struct Cer{
	double r;
	Vec cp;
}Cer;

double vabs(Vec a)
{
	return sqrt(a.x*a.x+a.y*a.y);
}

double ch(Vec a,Vec b,Cer c)
{
	if(dot(b-a,c.cp-a)<EPS)return vabs(b-a);
	if(dot(a-b,c.cp-b)<EPS)return vabs(c.cp-b);
	return abs(det(b-a,c.cp-a))/vabs(b-a);
}

int chC(Vec a,Cer c)
{
	return (a.x-c.cp.x)*(a.x-c.cp.x)+(a.y-c.cp.y)*(a.y-c.cp.y)<=c.r*c.r?1:0;
}

int N,M,i,j,f;
double m,d;
Cer W[100];

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<N;i++)
			scanf("%lf%lf%lf",&W[i].cp.x,&W[i].cp.y,&W[i].r);
		scanf("%d",&M);
		for(i=0;i<M;i++)
		{
			f=0;
			Vec t,s;
			scanf("%lf%lf%lf%lf",&t.x,&t.y,&s.x,&s.y);
			for(j=0;j<N;j++)
				if(ch(t,s,W[j])<=W[j].r&&!(chC(s,W[j])&&chC(t,W[j])))f=1;
			puts(f?"Safe":"Danger");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>

using namespace std;

int main() {
 int i,j,n,m,f;
 double a,b,c,r,mx[256],my[256],mr[256];
 vector<double> tx,ty,sx,sy;
 while(cin >> n) {
	 if (n==0) break;
	 for (i=0;i<n;i++)  cin >> mx[i] >> my[i] >> mr[i];
	 cin >> m;
	 for (i=0;i<m;i++) { cin >> a >> b >> c >> r; tx.push_back(a); ty.push_back(b); sx.push_back(c); sy.push_back(r);}
	 for (i=0;i<m;i++) { 
		 for (j=0,f=0;j<n;j++) {
			 a=sqrt((tx[i]-sx[i])*(tx[i]-sx[i])+(ty[i]-sy[i])*(ty[i]-sy[i]));
			 b=sqrt((tx[i]-mx[j])*(tx[i]-mx[j])+(ty[i]-my[j])*(ty[i]-my[j]));
			 c=sqrt((sx[i]-mx[j])*(sx[i]-mx[j])+(sy[i]-my[j])*(sy[i]-my[j]));
			 r=sqrt(c*c-(a*a-b*b+c*c)*(a*a-b*b+c*c)/(4*a*a));
			 if (b<mr[j] && c<mr[j]) continue;
			 if ((b<=mr[j] && c>mr[j]) || (b>mr[j] && c<=mr[j])) f=1;
             if (mr[j]+0.0001>=r && sqrt(b*b-r*r)+sqrt(c*c-r*r)<=a) f=1;
			 }
		 if (f==1) cout << "Safe" << endl; else cout << "Danger" << endl;
	 }
	 tx.clear(); ty.clear(); sx.clear(); sy.clear();
 }
 return 0;
}

C++: #include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
const double EPS=1e-5;

double add(double a,double b)
{
	if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}

typedef struct Vec{
	double x,y;
	Vec(){}
	Vec(double x,double y):x(x),y(y){}
	Vec operator +(Vec v){return Vec(add(x,v.x),add(y,v.y));}
	Vec operator -(Vec v){return Vec(add(x,-v.x),add(y,-v.y));}
	Vec operator *(double d){return Vec(x*d,y*d);}
}Vec;

double dot(Vec a,Vec b){return add(a.x*b.x,a.y*b.y);}
double det(Vec a,Vec b){return add(a.x*b.y,-a.y*b.x);}

typedef struct Cer{
	double r;
	Vec cp;
}Cer;

double vabs(Vec a)
{
	return sqrt(a.x*a.x+a.y*a.y);
}

double ch(Vec a,Vec b,Cer c)
{
	if(dot(b-a,c.cp-a)<EPS)return vabs(b-a);
	if(dot(a-b,c.cp-b)<EPS)return vabs(c.cp-b);
	return abs(det(b-a,c.cp-a))/vabs(b-a);
}

int chC(Vec a,Cer c)
{
	return (a.x-c.cp.x)*(a.x-c.cp.x)+(a.y-c.cp.y)*(a.y-c.cp.y)<c.r*c.r?1:0;
}

int N,M,i,j,f;
double m,d;
Cer W[100];

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<N;i++)
			scanf("%lf%lf%lf",&W[i].cp.x,&W[i].cp.y,&W[i].r);
		scanf("%d",&M);
		for(i=0;i<M;i++)
		{
			f=0;
			Vec t,s;
			scanf("%lf%lf%lf%lf",&t.x,&t.y,&s.x,&s.y);
			if(t.x!=s.x||t.y!=s.y)
			{
			for(j=0;j<N;j++)
				if(ch(t,s,W[j])<=W[j].r&&!(chC(s,W[j])&&chC(t,W[j])))f=1;
			}
			puts(f?"Safe":"Danger");
		}
	}
	return 0;
}