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<stdio.h>
#include<algorithm>
using namespace std;
int x[100];
int y[100];
int r[100];
bool CL_intersect(int ax,int ay,int bx,int by,int cx,int cy,int r){
	int acx=cx-ax;
	int acy=cy-ay;
	int bcx=cx-bx;
	int bcy=cy-by;
	int abx=bx-ax;
	int aby=by-ay;
	if(acx*acx+acy*acy>=r*r||bcx*bcx+bcy*bcy>=r*r){
		if(abx*acx+aby*acy<0){
			if(acx*acx+acy*acy<=r*r)return true;
		}else{
			if(abx*acx+aby*acy>abx*abx+aby*aby){
				if(bcx*bcx+bcy*bcy<=r*r)return true;
			}else if(acx*acx+acy*acy-(long long)(abx*acx+aby*acy)*(abx*acx+aby*acy)/(abx*abx+aby*aby)<=r*r)return true;
		}
	}
	return false;
}
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(CL_intersect(c,d,e,f,x[j],y[j],r[j]))ok=true;
			}
			if(ok)printf("Safe\n");
			else printf("Danger\n");
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;
/* àÏ */
static inline double inp(const P &a, const P &b){
  return (conj(a)*b).real();
}
/* OÏ */
static inline double outp(const P &a, const P &b){
  return (conj(a)*b).imag();
}

class Line{
public:
  P p; /* position */
  P d; /* direction */
  Line(){}
  Line(P pos, P dir){p=pos; d=dir/abs(dir);}
};

/* _Æûü©ç */
Line LineDirect(P pos, P dir){
  return Line(pos, dir);
}
/* 2_©ç */
Line LinePos(P p1, P p2){
  return Line(p1, p2-p1);
}

/* _Æ¼üÌ£ */
double dist(const Line &l, const P &p){
  return std::abs(outp(l.d, p-l.p) / abs(l.d));
}

P crossPoint(const Line &l1, const Line &l2){
  double num = outp(l2.d, l2.p-l1.p);
  double denom = outp(l2.d, l1.d);
  return P(l1.p + l1.d * num/denom);
}
int ccw(P p0, P p1, P p2){
  P d1 = p1-p0;
  P d2 = p2-p0;
  double dx1 = d1.real(), dx2 = d2.real();
  double dy1 = d1.imag(), dy2 = d2.imag();

  if(dx1*dy2 > dy1*dx2) return  1;//½vñè
  if(dx1*dy2 < dy1*dx2) return -1;//vñè
  if((dx1*dx2 < 0) || (dy1*dy2 < 0)) return -1;
  if((dx1*dx1+dy1*dy1) < (dx2*dx2+dy2*dy2)) return 1;
  return 0;
}

int main(){
  int n;
  scanf("%d",&n);
  P o[n];
  double r[n];
  REP(i,n)
    scanf("%lf%lf%lf",&o[i].real(),&o[i].imag(),&r[i]);
  int m;
  scanf("%d",&m);
  while(m --> 0){
    P p[2];
    scanf("%lf%lf%lf%lf",&p[0].real(),&p[0].imag(),&p[1].real(),&p[1].imag());

    bool ans = false;
    REP(i,n){
      double d1 = abs(p[0] - o[i]) - r[i];
      double d2 = abs(p[1] - o[i]) - r[i];
      if(d1 * d2 < 0){
        ans = true;
        break;
      }
      if(d1 < 0 && d2 < 0)
        continue;
      if(dist(LinePos(p[0],p[1]), o[i]) > r[i] + 1e-10)
        continue;

      /*
      Line l = LineDirect(o[i], (p[0]-p[1])*P(0,1));
      P pp = crossPoint(l, LinePos(p[0],p[1]));
      if(ccw(p[0],p[1],pp) == 0){
        ans = true;
        break;
      }
      */
      P pp = (p[1] - o[i]) / (p[0] - o[i]);
      if(pp.real() + 1e-10 <= 0){
        ans = true;
        break;
      }
    }
    puts(ans?"Safe":"Danger");
  }
  return 0;
}

C++: #include <iostream>
#include <cassert>
#include <cmath>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;


typedef complex<double> P;
typedef vector<P> G;

#define EPS			(1e-10)
#define PI			(3.14159265358979323846)


#define X(a)		( (a).real() )
#define Y(a)		( (a).imag() )
#define EQ(a,b)		( -EPS<(a)-(b) && (a)-(b)<EPS )
#define EQV(a,b)	( EQ(X(a),X(b)) && EQ(Y(a),Y(b)) )

#define unit(a)		( (a)/abs(a) )
#define normal(a)	( (a)*P(0,1) )
#define dot(a,b)	( X((a)*conj(b)) )
#define cross(a,b)	( Y(conj(a)*(b)) )

double distLP(P a, P b, P p)
{
	return abs(cross(b-a, p-a))/abs(b-a);
}

bool intersectSC(P a, P b, P c, double r)
{
	if( !(distLP(a,b,c) <= r + EPS) ) return false;

	double da=abs(c-a);
	double db=abs(c-b);

	if(da< r-EPS && db< r-EPS) return false;
	if(da<=r+EPS || db<=r+EPS) return true;

	return dot(c-a,b-a)*dot(c-b,b-a) <= EPS;
}


int main()
{
	int n,m,i;
	double t;
	P a,b,p;
	vector<P> c;
	vector<double> r;

	while(cin >> n, n)
	{
		for(i=0; i<n; i++)
		{
			cin >> X(p) >> Y(p) >> t;
			c.push_back(p);
			r.push_back(t);
		}

		cin >> m;
		while(m--)
		{
			cin >> X(a) >> Y(a) >> X(b) >> Y(b);
			for(i=0; i<n; i++)
			{
				if(intersectSC(a,b,c[i],r[i]))
				{
					cout << "Safe" << endl;
					break;
				}
			}
			if(i==n)
			{
				cout << "Danger" << endl;
			}
		}
	}
}