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<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

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

#define REP(i,n) for(int i=0; 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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;
/* àÏ */
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);
}

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

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

int main(){
  int n;
  scanf("%d",&n);
  P o[n];
  double r[n];
  REP(i,n)
    scanf("%lf%lf%lf",&o[i].real(),&o[i].imag(),&r[i]);
  int m;
  scanf("%d",&m);
  while(m --> 0){
    P p[2];
    scanf("%lf%lf%lf%lf",&p[0].real(),&p[0].imag(),&p[1].real(),&p[1].imag());

    bool ans = false;
    if(p[0] != p[1])
      REP(i,n){
        double d1 = abs(p[0] - o[i]) - r[i];
        double d2 = abs(p[1] - o[i]) - r[i];
        if((d1 < 0 && d2 > 0) || (d1 > 0 && d2 < 0)){
          ans = true;
          break;
        }
        if(d1 < 0 && d2 < 0)
          continue;
        if(dist(LinePos(p[0],p[1]), o[i]) > r[i])
          continue;

        Line l = LineDirect(o[i], (p[0]-p[1])*P(0,1));
        P pp = crossPoint(l, LinePos(p[0],p[1]));
        P l1 = pp - p[0];
        P l2 = pp - p[2];
        if((l1 / l2).real() < 0){
          ans = true;
          break;
        }
      }
    puts(ans?"Safe":"Danger");
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-5;

using namespace std;

typedef complex<double> Point;

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();
}
double distance_line_point(const Point& a, const Point& b, const Point& point)
{
	return abs(cross(a-b, point-b) / abs(a-b));
}
double distance_linesegment_point(const Point& a, const Point& b, const Point& point)
{
	if (dot(b-a, point-a) < Eps)
		return abs(a-point);
	else if (dot(a-b, point-b) <Eps)
		return abs(b-point);
	else
		return distance_line_point(a, b, point);
}

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		Point wall[126];
		int radius[126];
		for (int i = 0; i < n; ++i)
		{
			int a, b, r;
			scanf("%d %d %d", &a, &b, &r);
			wall[i] = Point(a, b);
			radius[i] = r;
		}

		int m;
		scanf("%d", &m);
		for (int i = 0; i < m; ++i)
		{
			int a, b, c, d;
			scanf("%d %d %d %d", &a, &b, &c, &d);
			Point tarou(a, b), oni(c, d);

			bool safe = false;
			for (int j = 0; j < n; ++j)
			{
				double EpsR = Eps + radius[j];
				if (abs(tarou - wall[j]) < EpsR && abs(oni - wall[j]) < EpsR)
					continue;

				if (distance_linesegment_point(tarou, oni, wall[j]) < EpsR)
				{
					safe = true;
					break;
				}
			}
			if (safe)
				puts("Safe");
			else
				puts("Danger");
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <utility>
using namespace std;

#define EPS 1e-8
#define sqr(x) ((x)*(x))
#define fi first
#define se second

class circle {
	public:
		int x, y, r;
		circle(int x, int y, int r) {
			this->x = x;
			this->y = y;
			this->r = r;
		}

		bool is_cross(int x1, int y1, int x2, int y2) {
			pair<int,int> range;
			int x0 = x, y0 = y;
			if(x1 == x2 && y1 == y2) {
				return false;
			}
			if(x1 == x2) {
				swap(x1, y1);
				swap(x2, y2);
				swap(x0, y0);
			}

			range.fi = min(x1, x2);
			range.se = max(x1, x2);

			double a, b;
			a = (double)(y2 - y1) / (x2 - x1);
			b = y1 - a * x1;

			double d;
			d = sqr(x0 - a * (b - y0)) - (1 + sqr(a)) * (sqr(x0) + sqr(b - y0) - sqr(r));

			if(d < 0)
				return false;

			double z, zz;
			z  = (x0 - a * (b - y0) - sqrt(d)) / (1 + sqr(a));
			zz = (x0 - a * (b - y0) + sqrt(d)) / (1 + sqr(a));

			if((range.fi < z && z < range.se) || (range.fi < zz && zz < range.se))
				return true;
			return false;
		}
};

int main(void) {
	int n, m;
	vector<circle> v;

	while(cin >> n, n) {
		for(int i = 0; i < n; i++) {
			int x, y, r;
			cin >> x >> y >> r;
			v.push_back(circle(x,y,r));
		}
		cin >> m;
		for(int i = 0; i < m; i++) {
			int x1, y1, x2, y2;
			bool flag = false;
			cin >> x1 >> y1 >> x2 >> y2;
			for(int j = 0; j < v.size(); j++) {
				if(v[j].is_cross(x1, y1, x2, y2))
					flag = true;
			}
			if(flag)
				cout << "Safe" << endl;
			else
				cout << "Danger" << endl;
		}
	}

	return 0;
}