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;
 
#define EPS 1e-7
 
class Point {
  public:
    double x, y;
    Point (double x = 0.0, double y = 0.0) : x(x),y(y) {}
    Point operator + (Point p) {
        return Point(x + p.x, y + p.y);
    }
    
    Point operator - (Point p) {
        return Point(x - p.x, y - p.y);
    }
    
    Point operator * (double a) {
        return Point(x * a, y * a);
    }
    
    Point operator / (double a) {
        return Point(x / a, y / a);
    }
    double abs() {
        return sqrt(norm());
    }
    double norm() {
        return x * x + y * y;
    }
};

double dot(Point a, Point b)
{
    return a.x * b.x + a.y * b.y;
}

double cross(Point a, Point b)
{
    return a.x * b.y - a.y * b.x;
}
 
class Segment {
  public:
    Point t, s;
    Segment(Point t, Point s) : t(t), s(s) {}
    Point projection(Point &p) {
	Point b = s - t;
	double d = dot(p-t,b) / b.norm();
	return t + b*d;
    }
};
 
class Circle {
  public:
    double x, y, r;
    Circle(double x = 0.0, double y = 0.0, double r = 0.0) :
        x(x), y(y), r(r) {}
};
 
int N;
Point t, s;
Circle ci[300];
 
bool check(Point p0, Point p1, Point p2)
{
    Point a = p1 - p0;
    Point b = p2 - p0;
    if (cross(a,b) > EPS) return 0;
    if (cross(a,b) < -EPS) return 0;
    if (dot(a,b) < -EPS) return 0;
    if (a.norm() < b.norm()) return 0;
    return 1;
}
 
bool getStateCS(Circle c, Segment seg)
{
    Point cp = Point(c.x, c.y);
    Point p = seg.projection(cp);
    Point pp = p - cp;
 
 
    Point a = seg.t - cp;
    Point b = seg.s - cp;
     
    if((a.abs() > c.r && b.abs() < c.r) ||
       (a.abs() < c.r && b.abs() > c.r) ) return 1;
    if(a.abs() > c.r && b.abs() > c.r){
	if(pp.abs()-EPS < c.r && check(seg.t, seg.s,p)){
	    return 1;
	}
    }
    return 0;
}
 
bool judge()
{
    Segment seg = Segment(t, s);
 
    for (int i = 0; i < N; i++) {
	if (getStateCS(ci[i], seg)) return 1;
    }
    return 0;
}
 
int main()
{
    int M;
    while (cin >> N, N) {
	for (int i = 0; i < N; i++) {
	    cin >> ci[i].x >> ci[i].y >> ci[i].r;
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
	    cin >> t.x >> t.y >> s.x >> s.y; 
	    if (judge()) {
		cout << "Safe" << endl;
	    } else {
		cout << "Danger" << endl;
	    }
	}
    }
    return 0;
}

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<numeric>
#include<cassert>

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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); 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()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

#include<complex>

#define EPS 1e-10

using std::complex;
typedef complex<double> P; /* _ */

static inline bool eq(const P &a, const P &b){
  return abs(a-b) < EPS;
}
/* àÏ */
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);
}

/* 2ÂÌ¼üÌð_ */
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);
}

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

/* p0, p1, p2ª
 * ½vñè:  1
 * vñè  : -1
 *
 * R_ª¼üãÉ éê
 * p0ªp2Æp1ÌÔÉ é: -1
 * p2ªp0Æp1ÌÔÉ é:  0
 * p1ªp0Æp2ÌÔÉ é:  1
 */
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;
}

template<class T> 
inline T dbl(T x){ return x * x; }

int main(){
  int n;
  while(n = getInt()){
    vector<P> c(n);
    vector<int> r(n);

    REP(i,n){
      c[i].real() = getInt();
      c[i].imag() = getInt();
      r[i]        = getInt();
    }

    int m = getInt();

    REP(cc,m){
      P tarou;
      P oni;

      tarou.real() = getInt();
      tarou.imag() = getInt();
      oni.real() = getInt();
      oni.imag() = getInt();

      bool ans = true;

      REP(i,n){
	bool tarouIn = ((int)(abs(tarou - c[i])+EPS)) < r[i];
	bool oniIn = ((int)(abs(oni - c[i])+EPS)) < r[i];

	if(tarouIn != oniIn){
	  ans = false;
	  break;
	}

	if(!tarouIn){
	  Line to(LinePos(tarou, oni));
	  if(((int)(dist(to, c[i]) - EPS)) < r[i]){
	    Line co(LineDirect(c[i], to.d * P(0, 1.0)));
	    P cross(crossPoint(to, co));
	    
	    double rate = ((oni - tarou) / (cross - tarou)).real();

	    if(rate >= 1.0){
	      ans = false;
	      break;
	    }
	  }
	}
      }

      puts(ans ? "Danger" : "Safe");
    }
 
  }
  return 0;
}