def result(r, d_r, D):
    discriminant = r ** 2 * d_r ** 2 - D ** 2

    return discriminant >= 0

lines, circles = [], []

N = int(input())

for x in range(N):
    lines.append(tuple(map(int, input().split())))

Q = int(input())

for x in range(Q):
    circles.append(tuple(map(int, input().split())))

intersections = 0

for circle in circles:
    lines_to_remove = []

    for line in lines:
        x_1, y_1, x_2, y_2 = line

        x_1 -= circle[0]
        y_1 -= circle[1]
        x_2 -= circle[0]
        y_2 -= circle[1]

        d_x = x_2 - x_1
        d_y = y_2 - y_1
        d_r = (d_x * d_x + d_y * d_y) ** 0.5
        D = x_1 * y_2 - x_2 * y_1

        if result(circle[2], d_r, D):
            intersections += 1
            lines_to_remove.append(line)

    for line in lines_to_remove:
        lines.remove(line)

    print(intersections)