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 <complex>
#include <vector>
#include <algorithm>

#define EPS 1e-10

using namespace std;

typedef complex<double> P;

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

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

bool intersectSP(const L &s, const P &p) {
    return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

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 distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

int main(){
    int n,m;                                     
    int x,y,r;
    int a,b;
    vector<C> circles;
    while(cin >> n && n){
        for(int i=0;i<n;i++){
            cin >> x >> y >> r;
            circles.push_back(C(P(x,y), r));
        }
        cin >> m;
        for(int i=0;i<m;i++){
            bool isok = false;
            cin >> x >> y;
            cin >> a >> b;
            L line = L(P(x,y), P(a,b));
            for(int j=0;j<n;j++){
                if(distanceSP(line, circles[j].p) - circles[j].r > EPS){
                }else{
                    if(abs(line[0]-circles[j].p) - circles[j].r < EPS &&
                       abs(line[1]-circles[j].p) - circles[j].r < EPS){
                    }else{
                        isok = true;
                    }             
                }
            }
            if(isok){
                cout << "Safe" << endl;
            }else{
                cout << "Danger" << endl;
            }
        }
    }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

#include <complex>
typedef complex<double> Point;
const double EPS = 1e-8;

// テ・ツ?・テ・ツ環崚」ツつケテ」ツδ暗」ツδェテ」ツδシテ」ツδ?」ツ?凝」ツつ嘉・ツョツ淌ヲツ閉ーテ、ツコツ古」ツ?、テ」ツつ津」ツ?ィテ」ツ?」テ」ツ?ヲ Point テ」ツ?ク
istream& operator >> ( istream &s, Point &a )
{
	double r, i;
	s >> r >> i;
	a = Point( r, i );
	return s;
}

// テ・ツ??ァツゥツ催ッツシツ暗」ツδ嘉」ツδε」ツδ暗ァツゥツ催ッツシツ?
double dot( const Point &a, const Point &b )
{
	return a.real() * b.real() + a.imag() * b.imag();
}

// テ・ツ、ツ姪ァツゥツ催ッツシツ暗」ツつッテ」ツδュテ」ツつケテァツゥツ催ッツシツ?
double cross( const Point &a, const Point &b )
{
	return a.real() * b.imag() - a.imag() * b.real();
}

// テァツ崢エテァツキツ?( p1, p2 ) テ」ツ?ィテァツつケ q テ」ツ?ョティツキツ敕ゥツ崢「
// include : cross
double distance_line_point( const Point &p1, const Point &p2, const Point &q )
{
	return abs( cross( p2 - p1, q - p1 ) ) / abs( ( p2 - p1 ) );
}

// テァツキツ堙・ツ按?( p1, p2 ) テ」ツ?ィテァツつケ q テ」ツ?ョティツキツ敕ゥツ崢「
// include : dot, distance_line_point
double distance_segment_point( const Point &p1, const Point &p2, const Point q )
{
	if ( EPS < dot( p2 - p1, q - p1 ) && EPS < dot( p1 - p2, q - p2 ) ) // テ・ツ楪づァツキツ堙」ツ?古、ツコツ、テ」ツつ湘」ツつ?
	{
		return distance_line_point( p1, p2, q );
	}
	else
	{
		return min( abs( p1 - q ), abs( p2 - q ) );
	}
}

// テァツキツ堙・ツ按?( p1, p2 ) テ」ツ?ィテ・ツ??( q, r ) テ」ツ?古、ツコツ、テ・ツキツョテ」ツ?凖」ツつ凝」ツ??
// include : distance_segment_point
bool segment_circle_intersect( const Point &p1, const Point &p2, const Point &q, const double r )
{
	if ( abs( p1 - q ) + EPS < r && abs( p2 - q ) + EPS < r )
	{
		return false;
	}
	else if ( r + EPS < abs( p1 - q ) && r + EPS < abs( p1 - q ) )
	{
		return distance_segment_point( p1, p2, q ) <= r + EPS;
	}
	else
	{
		return true;
	}
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	for ( int n; cin >> n, n; )
	{
		vector<Point> walls( n );
		vector<double> rs( n );
		REP( i, 0, n )
		{
			cin >> walls[i] >> rs[i];
		}

		int m;
		cin >> m;
		REP( i, 0, m )
		{
			Point t, s;
			cin >> t >> s;

			bool safe = false;
			REP( j, 0, n )
			{
				safe |= segment_circle_intersect( t, s, walls[j], rs[j] );
			}
			cout << ( safe ? "Safe" : "Danger" ) << endl;
		}
	}

	return 0;
}