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>
#include <cmath>
#include <array>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
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]);
}
bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}
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));
}
bool intersectCS(const C &c, const L &s){
    return (abs(c.p -s[0])+EPS > c.r || abs(c.p -s[1])+EPS > c.r)
        && distanceSP(s, c.p) < c.r +EPS;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<C> c(n);
        for(int i=0; i<n; i++){
            int x,y,r;
            cin >> x >> y >> r;
            c[i] = C(P(x,y), r);
        }

        int m;
        cin >> m;
        for(int i=0; i<m; i++){
            int sx,sy,tx,ty;
            cin >> sx >> sy >> tx >> ty;
            L s(P(sx,sy), P(tx,ty));
            bool safe = false;
            for(int j=0; j<n; j++){
                if(intersectCS(c[j], s)){
                    safe = true;
                    break;
                }
            }
            if(safe){
                cout << "Safe" << endl;
            }else{
                cout << "Danger" << endl;
            }
        }
    }
    return 0;
}

C++: #include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>


#define EPSILON 1e-9


class vector_t {
public:
  double x;
  double y;
  double z;

public:
  vector_t(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {};

public:
  double operator*(const vector_t& v) const {
    return x * v.x + y * v.y + z * v.z;
  };

  vector_t operator^(const vector_t& v) const {
    return vector_t(y * v.z - z * v.y,
                    z * v.x - x * v.z,
                    x * v.y - y * v.x);
  };

public:
  double length() const {
    return sqrt(*this * *this);
  };
};


class point_t {
public:
  double x;
  double y;
  double z;
  double w;

public:
  point_t(double x = 0, double y = 0, double z = 0, double w = 1) : x(x), y(y), z(z), w(w) {};
  
public:
  vector_t operator-(const point_t& p) const {
    return vector_t(x - p.x, y - p.y, z - p.z);
  };
};


class point_circle_intersect : public std::unary_function<point_t, bool>
{
public:
  point_circle_intersect(const point_t& o, double r) : o_(o), rr_(r * r + EPSILON) {};

public:
  bool operator()(const point_t& p) const {
    vector_t v(p - o_);

    return v * v < rr_;
  };

private:
  point_t o_;
  
  double rr_;
};


class segment_circle_intersect : public std::binary_function<point_t, point_t, bool>
{
public:
  segment_circle_intersect(const point_t& o, double r) : o_(o), rr_(r * r)
  {
  };

public:
  bool operator()(const point_t& p1, const point_t& p2) {
    vector_t p(p1 - o_), v(p2 - p1);

    double a = v * v;
    double b = v * p;
    double c = p * p - rr_;

    double d = b * b - a * c;

    if (d < 0)
      return false;
    
    d = sqrt(d);

    double t1 = (- b + d) / a;
    double t2 = (- b - d) / a;

    return ! (std::max(t1, t2) < -EPSILON || 1 + EPSILON < std::min(t1, t2));
  };

private:
  point_t o_;

  double rr_;
};


int main(int argc, char** argv)
{
  while (1) {
    int n, m;

    std::cin >> n;

    if (n == 0)
      break;
    
    std::vector<point_t> ws(n);
    std::vector<double>  rs(n);

    for (int i = 0; i < n; i ++)
      std::cin >> ws[i].x >> ws[i].y >> rs[i];

    std::cin >> m;

    for (int j = 0; j < m; j ++) {
      point_t t, s;

      std::cin >> t.x >> t.y >> s.x >> s.y;

      bool safe = false;

      for (int i = 0; i < n; i ++) {
        point_circle_intersect fn(ws[i], rs[i]);

        if (fn(t) && fn(s)) {
          ;
        }
        else if ((safe = segment_circle_intersect(ws[i], rs[i])(t, s))) {
          break;
        }
      }

      std::cout << (safe ? "Safe" : "Danger") << std::endl;
    }
  }

  return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<algorithm>
const double EPS=1e-10;

struct Vec{double x,y;};
struct Cer{double r;Vec cp;}W[100];


double D(Vec a){return hypot(a.x,a.y);}
double dot(Vec a,Vec b){return a.x*b.x+a.y*b.y;}
double det(Vec a,Vec b){return a.x*b.y-a.y*b.x;}

Vec F(Vec a,Vec b){Vec p={a.x-b.x,a.y-b.y};return p;}

double ch(Vec a,Vec b,Vec c)
{
	if(dot(F(b,a),F(c,a))<EPS)return D(F(c,a));
	if(dot(F(a,b),F(c,b))<EPS)return D(F(c,b));
	return fabs(det(F(b,a),F(c,a)))/D(F(b,a));
}

int N,M,i,j,f;
double m,d;

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<N;i++)
			scanf("%lf%lf%lf",&W[i].cp.x,&W[i].cp.y,&W[i].r);
		scanf("%d",&M);
		for(i=0;i<M;i++)
		{
			f=0;
			Vec t,s;
			scanf("%lf%lf%lf%lf",&t.x,&t.y,&s.x,&s.y);
			for(j=0;j<N;j++)
			{
				if(D(F(s,W[j].cp))<=W[j].r&&D(F(t,W[j].cp))<=W[j].r)continue;
				if(ch(t,s,W[j].cp)<=W[j].r)break;
			}
			puts(j==N?"Danger":"Safe");
		}
	}
	return 0;
}