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 <cstdio>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define EPS 1e-8
typedef complex<double> P;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

double dist(const P& a, const P& b)
{
	return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}

bool isIntoC(const L& l, const C& c)
{
	return dist(l[0], c.p)+EPS < c.r && dist(l[1], c.p)+EPS < c.r;
}

bool intersectSC(const L& l, const C& c)
{
	if(isIntoC(l, c)) return false;
	
	double vc=dot(l[1]-l[0], c.p-l[0]);
	if(vc<0)
	{
		return dist(l[0], c.p)<c.r+EPS;
	}
	
	double vv=dot(l[1]-l[0], l[1]-l[0]);
	
	if(vc > vv)
	{
		double d=dist(l[1], c.p);
		
		return d*d<c.r*c.r+EPS;
	}
	
	double cc=dot(c.p-l[0], c.p-l[0]);
	
	return cc-(vc/vv)*vc < c.r*c.r+EPS;
}

int main()
{
	int N,M;
	vector<C> walls;
	
	scanf("%d", &N);
	while(N--)
	{
		int x,y,r;
		scanf("%d%d%d", &x,&y,&r);
		walls.push_back(C(P(x,y), r));
	}
	
	scanf("%d", &M);
	while(M--)
	{
		int tx,ty,sx,sy;
		scanf("%d%d%d%d", &tx,&ty,&sx,&sy);
		bool g=false;
		for(int i=0; i<walls.size(); i++)
		{
			if(intersectSC(L(P(tx,ty),P(sx,sy)), walls[i]))
			{
				g=true;
				break;
			}
		}
		
		puts((g?"Safe":"Danger"));
	}
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int x[100];
int y[100];
int r[100];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d%d%d",x+i,y+i,r+i);
		int b;
		scanf("%d",&b);
		for(int i=0;i<b;i++){
			int c,d,e,f;
			scanf("%d%d%d%d",&c,&d,&e,&f);
			bool ok=false;
			for(int 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)printf("Safe\n");
			else printf("Danger\n");
		}
	}
}

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

double add(double a,double b){return a+b;}
typedef struct Vec{
	double x,y;
}Vec;
typedef struct Cer{double r;Vec cp;}Cer;

double dot(Vec a,Vec b){return a.x*b.x+a.y*b.y;}
double det(Vec a,Vec b){return a.x*b.y-a.y*b.x;}
double D(Vec a){return hypot(a.x,a.y);}
Vec F(Vec a,Vec b){Vec p={a.x-b.x,a.y-b.y};return p;}

double ch(Vec a,Vec b,Vec c)
{
	if(dot(F(b,a),F(c,a))<EPS)return D(F(b,a));
	if(dot(F(a,b),F(c,b))<EPS)return D(F(c,b));
	return fabs(det(F(b,a),F(c,a)))/D(F(b,a));
}

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(D(F(s,W[j].cp))<=W[j].r&&D(F(t,W[j].cp))<=W[j].r)continue;
				if(ch(t,s,W[j].cp)<=W[j].r)
					f=1;
			}
			puts(f?"Safe":"Danger");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

struct P{
    P(){}
    P(ll _r, ll _i):r(_r), i(_i){}
    void real(const ll& v){r = v;}
    void imag(const ll& v){i = v;}
    ll r, i;
};

ll real(const P& p){return p.r;}
ll imag(const P& p){return p.i;}
ll norm(const P& p){ll r = real(p), i = imag(p); return r * r + i * i;}

P operator+(const P& lhs, const P& rhs){
    return P(real(lhs)+real(rhs), imag(lhs)+imag(rhs));
}
P operator-(const P& lhs, const P& rhs){
    return P(real(lhs)-real(rhs), imag(lhs)-imag(rhs));
}
P operator-(const P& p){
    return P(-real(p), -imag(p));
}

ll cross(const P& lhs, const P& rhs){
    return real(lhs)*imag(rhs) - imag(lhs)*real(rhs);
}

ll dot(const P& lhs, const P& rhs){
    return real(lhs)*real(rhs) + imag(lhs)*imag(rhs);
}

ll distance(const P& a, const P& b, const P& p){
    ll c = cross(p-a, b-a);
    return c * c;
}

bool doesLineCrossCircle(const P& a, const P& b, const P& cc, const ll& radius){
    if(distance(a, b, cc) > radius * radius * norm(b-a)){return false;}
    if(norm(a-cc) > radius * radius && norm(b-cc) > radius * radius){
        return dot(cc-a, b-a) * dot(cc-b, b-a) < 0;
    }
    return (norm(a-cc) < radius * radius) ^ (norm(b-cc) < radius * radius);
}

int N, M;
P wps[100100]; ll wrs[100100];

int main(){
    std::cin >> N;

    REP(i, N){
        ll re, im;
        std::cin >> re >> im >> wrs[i];

        wps[i].real(re); wps[i].imag(im);
    }

    std::cin >> M;
    
    REP(i, M){
        P taro, oni;
        ll re, im;
        std::cin >> re >> im;
        taro.real(re); taro.imag(im);
        std::cin >> re >> im;
        oni.real(re); oni.imag(im);

        bool f = false;
        REP(j, N){
            if(doesLineCrossCircle(taro, oni, wps[j], wrs[j])){
                f = true;
            }
        }

        if(f){
            puts("Safe");
        }else{
            puts("Danger");
        }
    }
}