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<EPS)
	{
		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 <iostream>
#include <complex>
#include <vector>
#include <algorithm>

#define EPS 1e-7

using namespace std;

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);
}

bool intersectSP(const L &s, const P &p) {
    return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

int main(){
    int n,m;                                     
    double x,y,r;
    double a,b;

    while(cin >> n && n){
        vector<C> circles;
        bool isok = false;
        for(int i=0;i<n;i++){
            cin >> x >> y >> r;
            circles.push_back(C(P(x,y), r));
        }
        cin >> m;
        for(int i=0;i<m;i++){
            isok = false;
            cin >> x >> y;
            cin >> a >> b;
            L line = L(P(x,y), P(a,b));
            for(int j=0;j<n;j++){
                if((abs(line[0]-circles[j].p) < circles[j].r &&
                    abs(line[1]-circles[j].p) < circles[j].r) ||
                   distanceSP(line, circles[j].p) > circles[j].r){
                }else{
                    isok = true;
                }
            }
            if(isok){
                cout << "Safe" << endl;
            }else{
                cout << "Danger" << endl;
            }
        }
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define EPS 1e-9


double AB(int tx,int ty,int sx,int sy){
    double x = tx-sx;
    double y = ty-sy;
    return sqrt( (x*x)+(y*y) );
}


double inner(int ax,int ay,int bx,int by){
	return ax*bx + ay*by;
}

bool isCross(int wx,int wy,int r,  int tx,int ty,int sx,int sy){
	//	cout<<tx<<" "<<sx<<" "<<wy<<" "<<ty<<" "<<sy<<" "<<wx<<endl;
	double vc = inner( tx-sx,ty-sy,wx-sx,wy-sy );
//	cout<<vc<<endl;
	if( vc <0 )
		if( AB(sx,sy,wx,wy)<=r+EPS )return true;
		else return false;
//	if( vc>=AB(sx,sy,tx,ty) )
	if( vc>=(sx-tx)*(sx-tx) + (sy-ty)*(sy-ty) )
		if( AB(sx,sy,wx,wy)<=r+EPS )return true;
		else return false;

    int cr = (tx-sx)*(wy-sy) - (ty-sy)*(wx-sx);
//    cout<<cr<<endl;
    double num = (double)cr/(double)( AB(tx,ty,sx,sy) );
//    cout<<fabs(num)<<" "<<r-EPS<<endl;
    if( fabs(num) < r+EPS )return true;

    return false;
}

int isInCircle(int wx,int wy,int r,  int tx,int ty,int sx,int sy){
    int ret=0;
    if( sqrt((wx-tx)*(wx-tx) + (wy-ty)*(wy-ty))<=r+EPS )ret++;
    if( sqrt((wx-sx)*(wx-sx) + (wy-sy)*(wy-sy))<=r+EPS )ret++;
    return ret;
}


int main(){
    while(1){
        int n,m;
        int wx[200],wy[200],r[200];
        int tx[1000],ty[1000],sx[1000],sy[1000];
        cin>>n;
        if(n==0)break;
        rep(i,n) cin>>wx[i]>>wy[i]>>r[i];

        cin>>m;
        rep(i,m) cin>>tx[i]>>ty[i]>>sx[i]>>sy[i];
    

        rep(i,m){
            bool flag=false;
            rep(j,n){
                int circle = isInCircle(wx[j],wy[j],r[j],tx[i],ty[i],sx[i],sy[i]);
                bool Cross = isCross(wx[j],wy[j],r[j],tx[i],ty[i],sx[i],sy[i]);
                if( (circle==0 && Cross) || circle==1 ){
                    flag = true;
                    break;
                }
            }
            if(flag)cout<<"Safe"<<endl;
            else cout<<"Danger"<<endl;
        } 
    }
}