#include <iostream>
#include <vector>
#include <complex>
using namespace std;
typedef complex<double> P;
static const double EPS = 1e-8;

double dot(const P& p, const P& q)
{
  return p.real()*q.real() + p.imag()*q.imag();
}

double norm2(const P& p)
{
  return dot(p, p);
}

P perpendicular_foot(const P& p, const P line[2])
{
  const double t = dot(p - line[0], line[0] - line[1]) / norm2(line[0] - line[1]);
  return line[0] + t*(line[0]-line[1]);
}

bool intersect_point_segment(const P& p, const P seg[2])
{
  return abs(seg[0]-p) + abs(seg[1]-p) - abs(seg[1]-seg[0]) < EPS;
}

int main()
{
  int n;
  cin >> n;
  vector<pair<P,double> > walls(n);
  for (int i = 0; i < n; i++) {
    cin >> walls[i].first.real() >> walls[i].first.imag() >> walls[i].second;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    P taro, oni;
    cin >> taro.real() >> taro.imag() >> oni.real() >> oni.imag();
    const P line[] = {taro, oni};
    vector<pair<P,double> >::const_iterator it(walls.begin());
    for (; it != walls.end(); ++it) {
      const double d1 = abs(taro - it->first);
      const double d2 = abs(oni - it->first);
      if (d1 < it->second && d2 < it->second) {
      } else if (d1 > it->second && d2 > it->second) {
        const P h = perpendicular_foot(it->first, line);
        if (intersect_point_segment(h, line) && abs(h - it->first) - it->second < EPS) {
          cout << "Safe" << endl;
          goto NEXT;
        }
      } else {
        cout << "Safe" << endl;
        goto NEXT;
      }
    }
    cout << "Danger" << endl;
NEXT:
    ;
  }
  return 0;
}