require 'matrix'

until (num = $<.gets.to_i).zero?
  circles = Array.new(num) do
    x, y, r = $<.gets.split.map(&:to_r)
    [Vector[x, y], r]
  end
  
  $<.gets.to_i.times do
    tx, ty, sx, sy = $<.gets.split.map(&:to_r)
    ta  = Vector[tx, ty]
    oni = Vector[sx, sy]
    v = ta - oni
    n = Vector[v[1], -v[0]].normalize
    f = circles.map do |o, r|
      pos1 = (oni - o).norm < r
      pos2 = (ta  - o).norm < r
      if pos1 and pos2
        false
      elsif !pos1 and !pos2
        s, t = Matrix.columns([v, -n]).lup.solve(o - oni).to_a
        s.between?(0, 1) and t.abs <= r
      else
        true
      end
    end.any?
    puts f ? "Safe" : "Danger"
  end
end
