import math 

linije = []
scenario = []
mali = []

def UKrugu(xl,yl,ul,vl, x, y, r):
    a=yl-vl
    b=ul-xl
    c=xl*vl - ul*yl
    dist = ((abs(a * x + b * y + c))/math.sqrt(a * a + b * b)) 
    if (r == dist): 
        return True
    elif(r>dist):
        return True
    else: 
        return False
    

n = int(input())
for i in range(n):
    linije.append(tuple(map(int, input().split())))
q = int(input())
scenario = [0]*q
for i in range(q):
    x,y,r = map(int,input().split())
    scenario[i] += len(mali)
    p=0
    while (p<n):
        if(UKrugu(linije[p][0],linije[p][1],linije[p][2],linije[p][3], x,y,r)==True):
            scenario[i]+=1
            mali.append(linije[p])
            del linije[p]
            n-=1
        else:
            p+=1        
    print(scenario[i])