[pascal]
var
nplayer, nball, code : integer;
player : array[1..20, 1..3]of longint;
i : integer;
a, b, c, d, e, f, g : double;
x, y : double;
r, t : double;
s : string;
function ceiling(x : double) : double;
begin
if abs(int(x) - x) < 1e-7 then
ceiling := x
else
ceiling := int(x) + 1;
end;
function caught : boolean;
var i : integer; dis : double;
begin
for i := 1 to nball do
begin
dis := sqr(x - player[i, 1]) + sqr(y - player[i, 2]);
if dis <= sqr(t) * sqr(player[i, 3]) then
begin caught := true; exit; end;
end;
caught := false;
end;
begin
readln(s); delete(s, 1,

val(s, nplayer, code);
for i := 1 to nplayer do
readln(player[i, 1], player[i, 2], player[i, 3]);
readln(s); delete(s, 1, 6);
val(s, nball, code);
for i := 1 to nball do
begin
readln(a, b, c, d, e, f, g);
r := b * b - 4 * a * c;
t := (-b - sqrt(r)) / (2 * a);
t := ceiling(t);
x := d * t + e;
y := f * t + g;
if (x < 0) or (y < 0)then
writeln('Ball ', i, ' was foul at (', x :0 :0, ',', y:0:0, ')')
else
if caught then
writeln('Ball ', i, ' was caught at (', x :0 :0, ',', y:0:0, ')')
else
writeln('Ball ', i, ' was safe at (', x :0 :0, ',', y:0:0, ')')
end;
end.
[/pascal]