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++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(_Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,_Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

inline D inprd(const P &a, const P &b){ return (conj(a) * b).X; }
inline D outprd(const P &a, const P &b){ return (conj(a) * b).Y; }

D distance_ls_p(const P &a, const P &b, const P &c){
    if(inprd(b-a, c-a) < EPS) return abs(c-a);
    if(inprd(a-b, c-b) < EPS) return abs(c-b);
    return abs(outprd(b-a, c-a)) / abs(b-a);
}

string solve(vector<pair<pair<int,int>, int> > &vn, int tx, int ty, int sx, int sy){
    P t(tx,ty), s(sx,sy);
    FOREACH(it, vn){
        P n(it->first.first, it->first.second);
        int r = it->second;
        // それぞれ内と外に居る
        if(abs(t-n) < r && abs(s-n) > r) return "Safe";
        if(abs(t-n) > r && abs(s-n) < r) return "Safe";
        // どちらも内に居る
        if(abs(t-n) < r && abs(s-n) < r) continue;
        // どちらも外に居る
        if(distance_ls_p(s,t,n) <= r + EPS) return "Safe";
    }
    return "Danger";
}

int main(){
    int n, m;
    vector<pair<pair<int,int>, int> > vn;
    while(cin >> n && n){
        int x, y, r;
        REP(i,n){
            cin >> x >> y >> r;
            vn.pb(mp(mp(x,y),r));
        }
        cin >> m;
        int tx,ty,sx,sy;
        REP(i,m){
            cin >> tx >> ty >> sx >> sy;
            cout << solve(vn, tx,ty,sx,sy) << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<complex>

typedef std::complex<double> P;

const double EPS = 1e-10;

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

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

// 線分abと点cの距離
double dist( const P& a, const P& b, const 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 );
}

int n;
P wpt[100];
double r[100];

std::istream& operator>> ( std::istream& in, P& p )
{
	if( in )
	{
		double x, y;
		in >> x >> y;
		p = P( x, y );
	}

	return in;
}

int main()
{
	while( std::cin >> n, n )
	{
		for( int i = 0; i != n; ++i )
			std::cin >> wpt[i] >> r[i];

		int m;
		std::cin >> m;
		for( int i = 0; i != m; ++i )
		{
			P s, t;
			std::cin >> s >> t;

			for( int j = 0; j != n; ++j )
			{
				if( !( abs( s - wpt[j] ) < r[j] && abs( t - wpt[j] ) < r[j] ) && dist( s, t, wpt[j] ) <= r[j] )
				{
					std::cout << "Safe" << std::endl;
					break;
				}
				else if( j == n - 1 )
					std::cout << "Danger" << std::endl;
			}
		}
	}

	return 0;
}