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 <bits/stdc++.h>
using namespace std;

typedef complex<double> P;
typedef pair<double, P> C;
vector<C> circles;
#define FST first
#define SND second
typedef pair<P, P> S;

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 distanceLP(S s, P a) {
  // d = |y||sin(th)| = |x||y|sin(th)/|x| = |cross(x, y)|/|x|
  return abs(cross(s.SND-s.FST, a-s.FST)) / abs(s.SND-s.FST);
}

double distanceSP(S s, P a) {
  // 2ベクトルのなす角が鈍角なら端点と１点との距離を返す
  if (dot(s.SND-s.FST, a-s.FST) < EPS) return abs(a-s.FST);
  if (dot(s.FST-s.SND, a-s.SND) < EPS) return abs(a-s.SND);
  
  return distanceLP(s, a);
}

int main() {
  int N;
  while(cin >> N && N) {
    circles.clear();
    circles.resize(N);
    for(int i=0; i<N; i++) {
      int x, y, r;
      cin >> x >> y >> r;
      circles[i] = C(r, P(x, y));
    }
    int Q; cin >> Q;
    while(Q--) {
      int x, y;
      cin >> x >> y; P taro(x, y);
      cin >> x >> y; P ogre(x, y);
      for(int i=0; i<N; i++) {
        if(distanceSP(S(taro, ogre), circles[i].SND) < circles[i].FST) {
          if(   abs(circles[i].SND-taro) > circles[i].FST
             || abs(circles[i].SND-ogre) > circles[i].FST) {
            cout << "Safe" << endl;
            goto EXIT;
          }
        }
      }
      
      cout << "Danger" << endl;
      
    EXIT:;
    }
  }
  
  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);}
}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 hypot(a.x,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 fabs(det(b-a,c.cp-a))/vabs(b-a);
}

int chC(Vec a,Cer c)
{
	return hypot(a.x-c.cp.x,a.y-c.cp.y)<=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(chC(s,W[j])&&chC(t,W[j]))continue;
				if(ch(t,s,W[j])<=W[j].r)
					f=1;
			}
			puts(f?"Safe":"Danger");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define NITENKAN(a, b) sqrt(((a.first - b.first) * (a.first - b.first)) + ((a.second - b.second) * (a.second - b.second)))

using namespace std;

bool checkFound(pair<double, double> taro, pair<double, double> oni, pair<pair<double, double>, double> syougai){
	double ac = NITENKAN(syougai.first, oni);
	double ab = NITENKAN(taro, oni);
	double bc = NITENKAN(syougai.first, taro);

	if(ac >= ab || bc >= ab){
		return true;
	}

	double naiseki =  (taro.first - oni.first) * (syougai.first.first - oni.first) + (taro.second - oni.second) * (syougai.first.second - oni.second);
	double cosSita = naiseki / (ab * ac);
	double t = ac * (1 - cosSita);//(sita * 3.14 / 180.0));
	t *= syougai.second;

	if(t > syougai.second){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int n = 0;

	while(cin >> n && n != 0){
		int m = 0;
		bool danger = false;
		vector<pair<pair<double, double>, double> > syougai(n);

		for(int i = 0; i < n; i++){
			cin >> syougai[i].first.first >> syougai[i].first.second >> syougai[i].second;
		}
		
		cin >> m;
		vector<pair<double, double> > taro(m);
		vector<pair<double, double> > oni(m);
		for(int j = 0; j < m; j++){
			//cinと比較、結果出力を書く
			cin >> taro[j].first >> taro[j].second >> oni[j].first >> oni[j].second;

			//太郎と鬼の現在位置における各障害物の影響を見る
			for(int l = 0; l < n; l++){
				//二人共円内
				if((NITENKAN(taro[j], syougai[l].first) < syougai[l].second) && (NITENKAN(oni[j], syougai[l].first) < syougai[l].second)){
					//円内に円がある可能性があるので他の障害物の影響を見る
					for(int a = l + 1; a < n; a++){
						danger = checkFound(taro[j], oni[j], syougai[a]);
						if(!danger){
							break;
						}
					}
				}
				//二人共円外
				else if((NITENKAN(taro[j], syougai[l].first) > syougai[l].second) &&  (NITENKAN(oni[j], syougai[l].first) > syougai[l].second)){
					danger = checkFound(taro[j], oni[j], syougai[l]);
				}
				else{
					danger = false;
				}
				if(!danger){
					break;		
				}
			}

			if(!danger){
				cout << "Safe" << endl;
			}
			else{
				cout << "Danger" << endl;
			}

		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define SQ(x) ((x)* (x))

using namespace std;

// 円と線分の当たり判定 http://r-force.seesaa.net/article/160353128.html //
bool jES(int sx1, int sy1, int sx2, int sy2, int x, int y, int r) {
    int d2;
    int a,b, c;
	
	a = sy2 - sy1;
	b = sx1 - sx2;
	c = -1 * (a * sx1 + b * sy1);  
	// d = abs(a*x+b*y+c)/sqrt(a*a+b*b)
	d2 = SQ(a*x+b*y+c);
	if(d2 > r*r * (a*a + b*b)) return false;
	
	if(((sx2-sx1)*(x-sx1)+(sy2-sy1)*(y-sy1)>0) &&
	   ((sx1-sx2)*(x-sx2)+(sy1-sy2)*(y-sy2)>0))  return true;
	
	return false;
}


int main(void){
 
int n, m;
int w[110][3];
int tx,ty,sx,sy;
	
	while(cin >> n){
		if(n==0 || cin.eof()) break;
		rep(i,n) cin >> w[i][0] >> w[i][1]>> w[i][2];
		
		cin >> m;
		rep(i,m){
			cin >> tx >> ty >> sx >> sy;
			bool ok = true;
			rep(j,n){
				if((SQ(tx-w[j][0]) + SQ(ty-w[j][1]) < SQ(w[j][2])) &&
				   (SQ(sx-w[j][0]) + SQ(sy-w[j][1]) < SQ(w[j][2]))) ok=false;
				else  ok = jES(tx,ty,sx,sy,w[j][0],w[j][1],w[j][2]);
		//		cout << "test:::" <<(ok?  "Safe": "Danger") << endl;
				if(ok) break;
			}
			cout << (ok? "Safe": "Danger") << endl;
		}
	}
}