#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define EPS 1e-7
int n, m, wall[100][3], pp[4];
bool jud;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> wall[i][0] >> wall[i][1] >> wall[i][2];
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		for(int j = 0; j < 4; j++){
			cin >> pp[j];
		}
		double dx = pp[0] - pp[2], dy = pp[1] - pp[3], kmk, spn;
		if(dx)
			kmk = dy / dx;
		else{
			for(int j = 0; j < n; j++){
				double a = 1, b = -2 * wall[j][1], c = (pp[0] - wall[j][0]) * (pp[0] - wall[j][0]) + wall[j][1] * wall[j][1] - wall[j][2] * wall[j][2];
				double D = b * b - 4 * a * c;
				if(D < -EPS){
					continue;
				}
				else if(D < 0){
					D = 0;
				}
				if(D >= 0){
					double aa = (sqrt(D) - b) / (2 * a);
					if(aa >= pp[1] && aa <= pp[3]){
						jud = 1;
						break;
					}
					if(aa >= pp[3] && aa <= pp[1]){
						jud = 1;
						break;
					}
					aa = (-sqrt(b * b - 4 * a * c) - b) / (2 * a);
				//	cout << aa << endl;
					if(aa >= pp[1] && aa <= pp[3]){
						jud = 1;
						break;
					}
					if(aa >= pp[3] && aa <= pp[1]){
						jud = 1;
						break;
					}
				} 
			}
			if(jud)
				cout << "Safe" << endl;
			else
				cout << "Danger" << endl;
			continue;
		}
		spn = -kmk * pp[0] + pp[1];
		jud = 0;
		for(int j = 0; j < n; j++){
			double a = 1 + kmk * kmk, b = -2 * wall[j][0] + 2 * kmk * spn - 2 * kmk * wall[j][1], c = wall[j][0] * wall[j][0] + wall[j][1] * wall[j][1] + spn * spn - 2 * spn * wall[j][1] - wall[j][2] * wall[j][2];
				double D = b * b - 4 * a * c;
				if(D < -EPS){
					continue;
				}
				else if(D < 0){
					D = 0;
				}
				if(D >= 0){
				double aa = (sqrt(D) - b) / (2 * a);
				if(aa >= pp[0] && aa <= pp[2]){
					jud = 1;
					break;
				}
				if(aa >= pp[2] && aa <= pp[0]){
					jud = 1;
						break;
				}
				aa = (-sqrt(b * b - 4 * a * c) - b) / (2 * a);
				if(aa >= pp[0] && aa <= pp[2]){
					jud = 1;
					break;
				}
				if(aa >= pp[2] && aa <= pp[0]){
					jud = 1;
					break;
				}
			}
		}
		if(jud)
			cout << "Safe" << endl;
		else
			cout << "Danger" << endl;
	}
}