#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

struct Circle{
	double x, y, r;
};

struct Segment{
	double x1, y1, x2, y2;
	double LengthSquared(){ return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); }
};

double CrossProduct2D(double x1, double y1, double x2, double y2){
	return x1 * y2 - x2 * y1;
}

double DotProduct2D(double x1, double y1, double x2, double y2){
	return x1 * x2 + y1 * y2;
}

bool isSegmentCircleIntersect(Circle c, Segment s){
	double r1 = (s.x1 - c.x) * (s.x1 - c.x) + (s.y1 - c.y) * (s.y1 - c.y) - c.r * c.r;
	double r2 = (s.x2 - c.x) * (s.x2 - c.x) + (s.y2 - c.y) * (s.y2 - c.y) - c.r * c.r;
	double d = CrossProduct2D(s.x2 - s.x1, s.y2 - s.y1, c.x - s.x1, c.y - s.y1) / sqrt(s.LengthSquared());
	if(r1 < 0 && r2 < 0)return false;
	if(d > c.r) return false;
	if(DotProduct2D(s.x2 - s.x1, s.y2 - s.y1, c.x - s.x1, c.y - s.y1) * DotProduct2D(s.x2 - s.x1, s.y2 - s.y1, c.x - s.x2, c.y - s.y2) <= 0) return true;
	if((c.x - s.x1) * (c.x - s.x1) + (c.y - s.y1) * (c.y - s.y1) <= c.r * c.r || (c.x - s.x2) * (c.x - s.x2) + (c.y - s.y2) * (c.y - s.y2) <= c.r * c.r) return true;
	return false;
}

int main(){
	int n, m, wx, wy, r, tx, ty, sx, sy, t;
	vector< Circle > circles;
	vector< Segment > segments;
	
	while(cin >> n, n){
		circles.resize(n);
		for(int i = 0; i < n; ++i){
			cin >> wx >> wy >> r;
			circles[i].x = wx;
			circles[i].y = wy;
			circles[i].r = r;
		}
		
		cin >> m;
		segments.resize(m);
		for(int i = 0; i < m; ++i){
			cin >> tx >> ty >> sx >> sy;
			segments[i].x1 = tx;
			segments[i].y1 = ty;
			segments[i].x2 = sx;
			segments[i].y2 = sy;
			t = 0;
			
			for(int j = 0; j < n; ++j){
				t += (isSegmentCircleIntersect(circles[j], segments[i]) ? 1 : 0);
			}
			
			cout << (t ? "Safe" : "Danger") << endl;
		}
	}
	return 0;
}