#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
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());
}
double distance_ls_p(P a, P b, P c) {
  if ( dot(b-a, c-a) < EPS ) return abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

int main(void){
  int n,m;
  while(cin>>n){
    if(n==0) break;
    vector<P> wall;
    vector<double> wall2;
    REP(i,n){
      double x,y,r;
      cin>>x>>y>>r;
      wall.push_back(P(x,y));
      wall2.push_back(r);
    }
    cin>>m;
    while(m--){
      double x1,y1,x2,y2;
      P p1,p2;
      cin>>x1>>y1>>x2>>y2;
      p1 = P(x1,y1);
      p2 = P(x2,y2);
      bool unsame = false;
      REP(i,n){
        if(abs(p1-wall[i])<wall2[i]+EPS||abs(p2-wall[i])<wall2[i]+EPS){
          if(!(abs(p1-wall[i])<wall2[i]+EPS&&abs(p2-wall[i])<wall2[i]+EPS)){
            unsame = true;
            break;
          }
        }
      }
      if(unsame){
        cout<<"Safe"<<endl;
      }else{
        bool cross = false;
        REP(i,n){
          if(distance_ls_p(p1,p2,wall[i])<wall2[i]+EPS&&abs(p1-wall[i])>wall2[i]){
            cross = true;
            break;
          }
        }
        if(cross){
          cout<<"Safe"<<endl;
        }else{
          cout<<"Danger"<<endl;
        }
      }
    }
  }
  return 0;
}