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<iostream>
#include<cmath>
using namespace std;
struct Point { long double px, py; };
struct Segment { Point p1, p2; };
Point Minus(const Point& a, const Point& b) { return Point{ a.px - b.px,a.py - b.py }; }
long double norm(const Point& a) { return a.px * a.px + a.py * a.py; }
long double abs(const Point& a) { return sqrtl(norm(a)); }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
long double dst(const Segment& a, const Point& b) { return dot(Minus(a.p2, a.p1), Minus(b, a.p1)) < 0.0 ? abs(Minus(b, a.p1)) : (dot(Minus(a.p1, a.p2), Minus(b, a.p2)) < 0.0 ? abs(Minus(b, a.p2)) : abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / abs(Minus(a.p2, a.p1)))); }
long double dst(const Point& a, const Point& b) { return abs(Minus(b, a)); }

int n, m; Point V, W, x[100]; long double r[100];
int main() {
	while (true) {
		cin >> n; if (n == 0)break;
		for (int i = 0; i < n; i++) { cin >> x[i].px >> x[i].py >> r[i]; }
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> V.px >> V.py >> W.px >> W.py;
			bool OK = false;
			for (int j = 0; j < n; j++) {
				if (dst(V, x[j]) <= r[j] && dst(W, x[j])>r[j])OK = true;
				else if (dst(V, x[j])>r[j] && dst(W, x[j]) <= r[j])OK = true;
				else if (dst(V, x[j])>r[j] && dst(W, x[j]) > r[j]) {
					if (dst(Segment{ V,W }, x[j]) <= r[j])OK = true;
				}
			}
			if (OK == true)cout << "Safe" << endl; else cout << "Danger" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <complex>
//#include <fstream>

using namespace std;

// deq notes ½Êô½É¨¯éxNgZ http://www.deqnotes.net/acmicpc/2d_geometry/

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

// àÏ (dot product) : a&#8901;b = |a||b|cosÆ
double dot(P a, P b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

// OÏ (cross product) : a~b = |a||b|sinÆ
double cross(P a, P b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

// _cªüªa,bãÉ é©È¢©(2)
int is_point_on_line(P a, P b, P c) {
  // |a-c| + |c-b| <= |a-b| Èçüªã
  return (abs(a-c) + abs(c-b) < abs(a-b) + EPS);
}

// _a,bð[_Æ·éüªÆ_cÆÌ£
double distance_ls_p(P a, P b, P c) {
  if ( dot(b-a, c-a) < EPS ) return abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

struct CIRCLE{
	P p;
	double r;
};

int main()
{
//	cut here before submit 
//	freopen("testcase.hide-and-seek", "r", stdin);
	int n, m;
	int i,j;

	while (cin >> n && n ) {
		vector <CIRCLE> c(n);
		for (i = 0; i < n; ++i ){
			cin >> c[i].p.real() >> c[i].p.imag() >> c[i].r;
		} // end for
		cin >> m;
		vector <P>  taro(m), oni(m);
		for (j = 0; j < m; ++j ){
			cin >> taro[j].real() >> taro[j].imag() >> oni[j].real() >> oni[j].imag();
		} // end for
		for (j = 0; j < m; ++j ){
			vector <bool> in_taro (n, false ), in_oni (n, false );
			for (i = 0; i < n; ++i ){
				double dis_t = abs (taro[j] - c[i].p );
				double dis_o = abs (oni[j] - c[i].p );
				if (dis_t < c[i].r ){ // in circle[i]
					in_taro[i] = true;
				} // end if
				if (dis_o < c[i].r ){
					in_oni[i] = true;
				} // end if
			} // end for
			bool match = true;
			for (i = 0; i < n; ++i ){
				if (in_taro[i] == in_oni[i] ){
					continue;
				}else{
					match = false;
					break;
				} // end if
			} // end for
			if (!match ){
				cout << "Safe" << endl;
				continue;
			} // end if

			bool found = true;
			for (i = 0; i < n; ++i ){
				double dis = distance_ls_p (taro[j], oni[j], c[i].p );
				if (!in_taro[i] && (is_point_on_line (taro[j], oni[j], c[i].p ) || dis <= c[i].r ) ) { 
					found = false;
					break;
				} // end if
			} // end for
			if (found ){
				cout << "Danger" << endl;
			}else{
				cout << "Safe" << endl;
			} // end if
		} // end for
	} // end loop
		
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const double EPS = 1e-12;
#define EQ(a,b) (abs((a)-(b)) < EPS)

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

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

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

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

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 distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}


int intersectSC(const L &s, const C &c) {
  int ins = 0;
  for(int i = 0; i < 2; i++ ) {
    if (abs(s[i]-c.p)<c.r) ins++;
    else if (EQ(abs(s[i]-c.p), c.r)) return 0;
  }
  if (ins == 2) return -1;
  if (ins == 1) return 1;
  double d = distanceLP(s, c.p);
  if (d-c.r > EPS) return -1;
  P nor=(s[0]-s[1]) * P(0, 1);
  if (ccw(c.p, c.p+nor, s[0]) * ccw(c.p, c.p+nor, s[1]) < 0) return 2;
  return -1;
}

int main() {
  int N;
  while(cin >>N && N){
    vector<int> x(N), y(N), r(N);
    REP(i, N) cin >>x[i] >>y[i] >>r[i];
    int M; cin >>M;
    REP(m, M){
      int tx, ty, sx, sy; cin >>tx >>ty >>sx >>sy;
      L l = L(P(tx, ty), P(sx, sy));
      bool f = true;
      REP(n, N) if(intersectSC(l, C(P(x[n], y[n]), r[n])) >= 0) f = false;
      cout <<(f ? "Danger" : "Safe") <<endl;
    }
  }
  return 0;
}