#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef double Real;
typedef complex<Real> P;

int n;
pair<P,Real> walls[125];

bool hit(pair<P,Real> wall, Real tx,Real ty,Real sx,Real sy){
    P o = wall.first;
    Real r = wall.second;
    P t = P(tx,ty);
    P s = P(sx,sy);
    // s to origin
    o -= s;
    t -= s;
    // t on x axis
    if(s==t)return false;
    o = (o / t) * abs(t);
    
    Real d = r*r - o.imag()*o.imag();
    if(d < 0.0)return false;
    Real x0 = o.real() + sqrt(d);
    Real x1 = o.real() - sqrt(d);
    Real tb = abs(t);
    if(0.0 <= x0 && x0 <= tb)return true;
    if(0.0 <= x1 && x1 <= tb)return true;
    return false;
}

int main(void){
    // Here your code !
    while(true){
        scanf("%d",&n);
        if(n==0)break;
        REP(i,n){
            Real x,y,r;
            scanf("%lf%lf%lf",&x,&y,&r);
            walls[i] = make_pair(P(x,y),r);
        }
        int m;
        scanf("%d",&m);
        while(m--){
            Real tx,ty,sx,sy;
            scanf("%lf%lf%lf%lf",&tx,&ty,&sx,&sy);
            bool ishit = false;
            REP(i,n)if(hit(walls[i],tx,ty,sx,sy)){
                ishit = true;
                break;
            }
            puts(ishit?"Safe":"Danger");
        }
    }
}