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 <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)) + EPS;

			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;

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

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

class Wall {
public:
    int x, y, r;
    Wall(int x, int y, int r) : x(x), y(y), r(r) {};
};

string solve(vector<Wall> &w, int tx, int ty, int sx, int sy) {
    for (int i=0; i<(int)w.size(); ++i) {
        bool inside_t = w[i].r * w[i].r >= (w[i].x - tx) * (w[i].x - tx) + (w[i].y - ty) * (w[i].y - ty);
        bool inside_s = w[i].r * w[i].r >= (w[i].x - sx) * (w[i].x - sx) + (w[i].y - sy) * (w[i].y - sy);
        if ((inside_t && !inside_s) || (!inside_t && inside_s)) {
            return "Safe";
        } else if (!inside_t && !inside_s) {
            if (sx == tx) {
                bool inside = abs(sx - w[i].x) <= w[i].r;
                if (inside && min(ty, sy) <= w[i].y && w[i].y <= max(ty, sy)) {
                    return "Safe";
                }
            } else {
                double a, b, x, y;
                a = (double)(sy - ty) / (sx - tx);
                b = ty - a * tx;
                x = (w[i].x + a * (w[i].y - b)) / (1 + a * a);
                y = a * x + b;
                bool inside = w[i].r * w[i].r >= (w[i].x - x) * (w[i].x - x) + (w[i].y - y) * (w[i].y - y);
                if (inside && min(tx, sx) <= x && x <= max(tx, sx) && min(ty, sy) <= y && y <= max(ty, sy)) {
                    return "Safe";
                }
            }
        }
    }
    return "Danger";
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<Wall> walls;
        int wx, wy, r;
        for (int i=0; i<n; ++i) {
            cin >> wx >> wy >> r;
            walls.push_back(Wall(wx, wy, r));
        }
        int m;
        cin >> m;
        int tx, ty, sx, sy;
        for (int i=0; i<m; ++i) {
            cin >> tx >> ty >> sx >> sy;
            cout << solve(walls, tx, ty, sx, sy) << endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// pair util
#define FST first
#define SND second

// range validator
#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

int const dx[] = {-1,0,1,0,-1,1,1,-1};
int const dy[] = {0,-1,0,1,-1,-1,1,1};

//////////////////////////////////////////////////////////////

#define EPS (1e-5)

typedef complex<double> P;
typedef pair<double, P> C;
typedef pair<P, P> S;

double dot(P a, P b) {
  return a.real()*b.real()+a.imag()*b.imag();
}

double cross(P a, P b) {
  return a.real()*b.imag()-a.imag()*b.real();
}

typedef S Line;
double distanceLP(Line l, P a) {
  P base = l.SND-l.FST;
  return cross(base, a-l.FST) / abs(base);
}

double distanceSP(S s, P a) {
  {
    P X = s.SND - s.FST, Y = a - s.FST;
    if(dot(X, Y) < EPS) return abs(Y);
  }
  {
    P X = s.FST - s.SND, Y = a - s.SND;
    if(dot(X, Y) < EPS) return abs(Y);
  }
  
  return distanceLP(s, a);
}

int main() {
  
  while(1) {
    int N;
    cin >> N; if(N == 0) break;
    
    vector<C> circles(N);
    
    for(int i=0; i<N; i++) {
      double x, y, r;
      cin >> x >> y >> r;
      circles[i] = C(r, P(x, y));
    }
    
    int Q; cin >> Q;
    while(Q--) {
      int x, y;
      cin >> x >> y; P taro(x, y);
      cin >> x >> y; P devil(x, y);
      
      bool ok = 0;
      for(int idx=0; idx<N; idx++) {
	if( distanceSP( S(taro, devil), circles[idx].SND ) < circles[idx].FST + EPS ) {
	  if( abs(taro-circles[idx].SND) > circles[idx].FST + EPS
	      || abs(devil-circles[idx].SND) > circles[idx].FST + EPS ) ok = 1;
	}
      }
      
      if(ok) cout << "Safe" << endl;
      else cout << "Danger" << endl;
    }
    
  }
  
  return 0;
}