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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-8

using namespace std;

struct Point 
{
    double x, y;
    Point(double x=0, double y=0) : x(x), y(y) {}

    Point operator+(const Point &o) const 
	{
        return Point(x+o.x, y+o.y);
    }

    Point operator-(const Point &o) const 
	{
        return Point(x-o.x, y-o.y);
    }
 
    Point operator*(const double m) const 
	{
        return Point(x*m, y*m);
    }
 
    Point operator/(const double d) const 
	{
        return Point(x/d, y/d);
    }

	bool operator < (const Point &a) const
	{
		return x == a.x ? y < a.y : x < a.x;
	}
 
    double cross(const Point &o) const 
	{
        return x * o.y - y * o.x;
    }
 
    double dot(const Point &o) const 
	{
        return x * o.x + y * o.y;
    }
 
    double atan() const 
	{
        return atan2(y, x);
    }

    double norm() const 
	{
        return dot(*this);
    }

	double distance (const Point &o) const 
	{
        return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y));
    }

	double distance_Line(const Point &a,const Point &b) const
	{
		Point p(x,y);

		Point d = b-a;

		if(d.x == 0 && d.y == 0)
		{
			return p.distance(a);
		}

		double r2 = d.x*d.x + d.y*d.y;
		double t = (d.x*(p.x - a.x) + d.y*(p.y - a.y)) / r2;

		if(t < 0)
		{
			return p.distance(a);
		}
		if(t > 1)
		{
			return p.distance(b);
		}

		Point c;
		c.x = (1-t) * a.x + t*b.x;
		c.y = (1-t) * a.y + t*b.y;
		return p.distance(c);
	}

	double area(const Point &a,const Point &b) const
	{
		double t = (a.x - x) * (b.y - y);
		double t2 = (a.y - y) * (b.x - x);
		double areas = abs(t-t2);
		return  areas/2;
	}
};


int main()
{
	int n;
	vector<Point> kp;
	vector<double> r;

	while(cin >> n && n)
	{
		double a,b,c,d;
		
		rep(i,n)
		{
			cin >> a>> b >> c;
			kp.push_back(Point(a,b));
			r.push_back(c);
		}

		int m;
		cin >> m;
		rep(i,m)
		{
			cin >> a >> b >> c >> d;
			Point p1(a,b);
			Point p2(c,d);

			bool flag = true;
			rep(j,kp.size())
			{
				double d1 = p1.distance(kp[j]);
				double d2 = p2.distance(kp[j]);

				//cout << "j:" << j << endl;

				if(d1 > r[j] && d2 < r[j])
				{
					flag = false;
					cout << "Safe" << endl;
					break;
				}
				else if(d1 < r[j] && d2 > r[j])
				{
					flag = false;
					cout << "Safe" << endl;
					break;
				}

				else if(d1 >= r[j] && d2 >= r[j])
				{
					double dd = kp[j].distance_Line(p1,p2);

					//cout << "dd:" << dd << endl;

					if(dd <= r[j])
					{
						flag = false;
						cout << "Safe" << endl;
						break;
					}
				}
			}
			if(flag)
			{
				std::cout << "Danger" << endl;
			}
		}


	}
	return 0;
}