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:
    i = 0
    while i != len(lines):
        line = lines[i]

        d_r = ((line[2] - line[0]) ** 2 + (line[3] - line[1]) ** 2) ** 0.5
        D = (line[0] - circle[0]) * (line[3] - circle[1]) - (line[2] - circle[0]) * (line[1] - circle[1])

        if circle[2] * circle[2] * d_r * d_r - D * D >= 0:
            intersections += 1
            lines.remove(line)
            i -= 1
        i += 1

    print(intersections)