#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

class Wall {
public:
    int x, y, r;
    Wall(int x, int y, int r) : x(x), y(y), r(r) {};
};

string solve(vector<Wall> &w, int tx, int ty, int sx, int sy) {
    for (int i=0; i<(int)w.size(); ++i) {
        bool inside_t = w[i].r * w[i].r >= (w[i].x - tx) * (w[i].x - tx) + (w[i].y - ty) * (w[i].y - ty);
        bool inside_s = w[i].r * w[i].r >= (w[i].x - sx) * (w[i].x - sx) + (w[i].y - sy) * (w[i].y - sy);
        if ((inside_t && !inside_s) || (!inside_t && inside_s)) {
            return "Safe";
        } else if (!inside_t && !inside_s) {
            if (sx == tx) {
                bool inside = abs(sx - w[i].x) <= w[i].r;
                if (inside && min(ty, sy) <= w[i].y && w[i].y <= max(ty, sy)) {
                    return "Safe";
                }
            } else {
                double a, b, x, y;
                a = (double)(sy - ty) / (sx - tx);
                b = ty - a * tx;
                x = (w[i].x + a * (w[i].y - b)) / (1 + a * a);
                y = a * x + b;
                bool inside = w[i].r * w[i].r >= (w[i].x - x) * (w[i].x - x) + (w[i].y - y) * (w[i].y - y);
                if (inside && min(tx, sx) <= x && x <= max(tx, sx) && min(ty, sy) <= y && y <= max(ty, sy)) {
                    return "Safe";
                }
            }
        }
    }
    return "Danger";
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<Wall> walls;
        int wx, wy, r;
        for (int i=0; i<n; ++i) {
            cin >> wx >> wy >> r;
            walls.push_back(Wall(wx, wy, r));
        }
        int m;
        cin >> m;
        int tx, ty, sx, sy;
        for (int i=0; i<m; ++i) {
            cin >> tx >> ty >> sx >> sy;
            cout << solve(walls, tx, ty, sx, sy) << endl;
        }
    }
    return 0;
}