#include <iostream>
#include <cassert>
#include <cmath>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;


typedef complex<double> P;
typedef vector<P> G;

#define EPS			(1e-10)
#define PI			(3.14159265358979323846)


#define X(a)		( (a).real() )
#define Y(a)		( (a).imag() )
#define EQ(a,b)		( -EPS<(a)-(b) && (a)-(b)<EPS )
#define EQV(a,b)	( EQ(X(a),X(b)) && EQ(Y(a),Y(b)) )

#define unit(a)		( (a)/abs(a) )
#define normal(a)	( (a)*P(0,1) )
#define dot(a,b)	( X((a)*conj(b)) )
#define cross(a,b)	( Y(conj(a)*(b)) )

double distLP(P a, P b, P p)
{
	return abs(cross(b-a, p-a))/abs(b-a);
}

bool intersectSC(P a, P b, P c, double r)
{
	if( !(distLP(a,b,c) <= r + EPS) ) return false;

	double da=abs(c-a);
	double db=abs(c-b);

	if(da< r-EPS && db< r-EPS) return false;
	if(da<=r+EPS || db<=r+EPS) return true;

	return dot(c-a,b-a)*dot(c-b,b-a) <= EPS;
}


int main()
{
	int n,m,i;
	double t;
	P a,b,p;
	vector<P> c;
	vector<double> r;

	while(cin >> n, n)
	{
		for(i=0; i<n; i++)
		{
			cin >> X(p) >> Y(p) >> t;
			c.push_back(p);
			r.push_back(t);
		}

		cin >> m;
		while(m--)
		{
			cin >> X(a) >> Y(a) >> X(b) >> Y(b);
			for(i=0; i<n; i++)
			{
				if(intersectSC(a,b,c[i],r[i]))
				{
					cout << "Safe" << endl;
					break;
				}
			}
			if(i==n)
			{
				cout << "Danger" << endl;
			}
		}
	}
}