Missile Command

Time limit1sMemory limit128 MB

Problem

As Chief Bureaucrat at Missile Command, you have recently noticed that the existing performance guidelines do not sufficiently penalize frivolous use of expensive ammunition. You must therefore write a new battle-summary analysis tool that also accounts for excess ammunition consumption during a battle.

A battle consists of the following elements.

  • Shots. A shot is a circularly exploding countermeasure. A shot has a fixed position and stays active for 2 seconds after it detonates. During that time its radius grows from 0 to 1 km and shrinks back to 0, following, for the time $t$ elapsed since detonation ($0 \le t \le 2$, in seconds): $$r = \sqrt{1 - (t - 1)^2}$$
  • The ground, at $y = 0$.
  • Missiles. A missile is a point particle that moves at constant velocity. It enters the battlefield at time $mt$ at position $(mx, my)$ and travels with velocity $(mdx, mdy)$; that is, at any time $T \ge mt$ its position is $(mx + mdx,(T - mt),\ my + mdy,(T - mt))$. If a missile collides with an active shot — that is, at some instant the missile's position lies inside that shot's disk (its distance to the center is at most the radius) — the missile is neutralized, and the shot persists. If a missile reaches the ground before being neutralized, it is considered to have hit its target.

Performance is scored on a simple point scale.

  • Every neutralized missile adds $1$ point.
  • Every missile that hits its target subtracts $5$ points.
  • Every unnecessary shot subtracts $20$ points. The number of unnecessary shots in a battle is the difference between the number of shots actually fired and the size of the minimum subset of those shots that would have neutralized the same number of missiles.

Input

The input is given in the following format (a legend follows).

nb
nm
mx my mdx mdy mt
...
ns
sx sy st
...
...

In the legend below, indentation means the indented block is repeated a number of times equal to the value of the preceding item.

  • $nb$ ($0 < nb$) — number of battles

    • $nm$ ($0 \le nm \le 20$) — number of missiles

      • $mx$, $my$ ($0.0 < my$) — missile entry position (in km)
      • $mdx$, $mdy$ — missile velocity (in km/s)
      • $mt$ ($0.0 \le mt$) — time, since the battle started, at which the missile enters (in seconds)
    • $ns$ ($0 \le ns \le 20$) — number of shots

      • $sx$, $sy$ ($1.0 \le sy$) — shot position at the moment of detonation (in km)
      • $st$ ($0.0 \le st$) — time, since the battle started, at which the shot detonates (in seconds)

Output

For each battle, output a single line containing that battle's score.