#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define NITENKAN(a, b) sqrt(((a.first - b.first) * (a.first - b.first)) + ((a.second - b.second) * (a.second - b.second)))

using namespace std;

bool checkFound(pair<double, double> taro, pair<double, double> oni, pair<pair<double, double>, double> syougai){
	double ac = NITENKAN(syougai.first, oni);
	double ab = NITENKAN(taro, oni);
	double bc = NITENKAN(syougai.first, taro);

	if(ac >= ab || bc >= ab){
		return true;
	}

	double naiseki =  (taro.first - oni.first) * (syougai.first.first - oni.first) + (taro.second - oni.second) * (syougai.first.second - oni.second);
	double cosSita = naiseki / (ab * ac);
	double t = ac * (1 - cosSita);//(sita * 3.14 / 180.0));
	t *= syougai.second;
	/*
	cout << "ac : " << ac << endl;
	cout << "ab : " << ab << endl;
	cout << "naiseki : " << naiseki << endl;
	cout << "cosSita : " << cosSita << endl;
	cout << "t : " << t << endl;
	*/

	if(t > syougai.second){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int n = 0;

	while(cin >> n && n != 0){
		int m = 0;
		bool danger = false;
		vector<pair<pair<double, double>, double>> syougai(n);

		for(int i = 0; i < n; i++){
			cin >> syougai[i].first.first >> syougai[i].first.second >> syougai[i].second;
		}
		
		cin >> m;
		vector<pair<double, double>> taro(m);
		vector<pair<double, double>> oni(m);
		for(int j = 0; j < m; j++){
			//cinと比較、結果出力を書く
			cin >> taro[j].first >> taro[j].second >> oni[j].first >> oni[j].second;

			//太郎と鬼の現在位置における各障害物の影響を見る
			for(int l = 0; l < n; l++){
				//二人共円内
				if((NITENKAN(taro[j], syougai[l].first) < syougai[l].second) && (NITENKAN(oni[j], syougai[l].first) < syougai[l].second)){
					//円内に円がある可能性があるので他の障害物の影響を見る
					for(int a = l + 1; a < n; a++){
						danger = checkFound(taro[j], oni[j], syougai[a]);
						if(!danger){
							break;
						}
					}
				}
				//二人共円外
				else if((NITENKAN(taro[j], syougai[l].first) > syougai[l].second) &&  (NITENKAN(oni[j], syougai[l].first) > syougai[l].second)){
					danger = checkFound(taro[j], oni[j], syougai[l]);
				}
				else{
					danger = false;
				}
				if(!danger){
					break;		
				}
			}

			if(!danger){
				cout << "SAFE" << endl;
			}
			else{
				cout << "DANGER" << endl;
			}

		}
	}
}