#include <iostream>
#include <cmath>
#include <map>
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;

class Point{
public:
  double x, y;
  Point(double x = 0, double y = 0): x(x), y(y){}
  Point operator + (Point p){ return Point(x + p.x, y + p.y); }
  Point operator - (Point p){ return Point(x - p.x, y - p.y); }
  Point operator * ( double a ){ return Point(a*x, a*y); }
  double abs(){ return sqrt(norm()); }
  double norm(){ return x*x + y*y; }
  bool operator < ( const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point &p) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};
typedef Point Vector;

struct Segment{
  Point p1, p2;
};
typedef Segment Line;

class Circle{
public:
  Point p;
  int r;
};

int n;
Circle c[100];

double dot(Vector a, Vector b){
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a, Vector b){
  return a.x*b.y - a.y*b.x;
}

double getDistanceLP(Line s, Point p){
  return abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}

bool is_cross(Circle c, Line l){
  double dist1 = (c.p - l.p1).abs();
  double dist2 = (c.p - l.p2).abs();
  bool f1 = false, f2 = false;
  if(dist1 < (double) c.r || abs(dist1 - c.r) < EPS) f1 = true;
  if(dist2 < (double) c.r || abs(dist2 - c.r) < EPS) f2 = true;
  if(f1 && f2) return false;
  else if(f1 || f2) return true;
  Point p1, p2, p3, p4;
  p1 = l.p1 - l.p2;
  p2 = l.p2 - l.p1;
  p3 = c.p - l.p2;
  p4 = c.p - l.p1;
  //cout << dot(p1, p3) << ' ' << dot(p2, p4);
  if(dot(p1, p3) >= 0 && dot(p2, p4) >= 0){
    //cout << '!';
    double d = getDistanceLP(l, c.p);
    //cout << "(" << d << ", " << c.r << ")";
    if(d < c.r || abs(d - c.r) < EPS) return true;
  }
  return false;
}

string solve(Line l){
  for(int i=0;i<n;i++){
    //cout << i <<  ' ';
    if(is_cross(c[i], l)){
      return "Safe";
    }
    //cout << endl;
  }
  return "Danger";
}

main(){
  int m;
  while(cin >> n){
    if(n == 0) break;
    for(int i=0;i<n;i++){
      cin >> c[i].p.x >> c[i].p.y >> c[i].r;
    }
    cin >> m;
    for(int i=0;i<m;i++){
      Line input;
      cin >> input.p1.x >> input.p1.y >> input.p2.x >> input.p2.y;
      cout << solve(input) << endl;
    }
  }
  return 0;
}