### main

loop do
  n = gets.to_i
  break if n == 0

  stars = []
  n.times do
    sx, sy, sz = gets.split.map(&:to_f)
    len = Math.sqrt(sx * sx + sy * sy + sz * sz)
    stars << [sx, sy, sz, len]
  end

  m = gets.to_i
  tss = []
  m.times do
    tx, ty, tz, th = gets.split.map(&:to_f)
    len = Math.sqrt(tx * tx + ty * ty + tz * tz)
    tss << [tx, ty, tz, len, Math.cos(th)]
  end
  #p [stars, tss]

  count = 0

  stars.each do |sx, sy, sz, slen|
    tss.each do |tx, ty, tz, tlen, cth|
      stc = (sx * tx + sy * ty + sz * tz) / (slen * tlen)
      if stc > cth
        count += 1
        break
      end
    end
  end
  
  puts count
end