Under construction

Still being built. Things may change

Simple Darts

Interview

Time limit1sMemory limit1024 MB

Summary
Given a circular board with w wedges and ring radii b, d, and s, sum the scores of each dart throw at (x, y) coordinates.
Level

Easy3 of 10

Topics
Geometry, Implementation
Solved
No attempts yet

Problem

Figure 1. Standard Dartboard

Darts is a fun game that needs little physical space, so many game rooms have a board. The standard dartboard (see Figure 1) has 6 concentric rings and 20 wedges. The wedges divide the board into regions, and each region has a fixed score. Figure 1 shows fewer than 20 wedges so that the picture stays clear. The innermost ring is a double bullseye. The second ring is a single bullseye. Beyond the second ring, each wedge scores from 1 to 20. Some of the gaps between rings act as double or triple modifiers.

A simpler version of the game has been proposed to attract younger players.

Problem

Figure 2. Example Simple Dartboard

The simpler version is shown in Figure 2. The board has exactly 3 concentric rings instead of 6. It may have fewer than 20 wedges, and all wedges are the same size. The scoring works as follows.

The board is centered at the origin (0,0)(0,0) of the Cartesian plane. ww is the number of wedges (8 in Figure 2). bb, dd, and ss are the radii of the smallest ring, the second smallest ring, and the largest ring.

The wedge directly above the positive x axis (Wedge 1 in Figure 2) scores 1 point. Moving counterclockwise, each wedge scores 1 more than the previous one, so the wedge directly below the positive x axis (Wedge 8 in Figure 2) scores ww. The circle of radius bb around the origin is the bullseye, and it always scores 50 points. The area between radii bb and dd is the double ring. A dart there scores twice the value of the surrounding wedge. The area between radii dd and ss is the single ring. A dart there scores the value of the surrounding wedge. A dart outside the board scores 0.

Given the layout of such a board centered at the origin and a list of dart throws, calculate the total score.

Input

The first line contains a positive integer nn, the number of test cases.

Each test case starts with a line of four integers ww, bb, dd, ss, separated by spaces. ww (2≤w≤202 \le w \le 20) is the number of equal-sized wedges. bb, dd, and ss (0<b<d<s<1000 < b < d < s < 100) are the radii of the bullseye, the double ring, and the single ring.

The next line contains tt (1≤t≤1001 \le t \le 100), the number of dart throws. Each of the following tt lines contains two real numbers xx and yy with three decimal places, where −100≤x,y≤100-100 \le x, y \le 100. No dart lands within 10−510^{-5} of any boundary (line or arc).

Output

For each test case, print the total score of all its dart throws as a single integer on its own line.

Examples1

  1. Example 1

    Input
    3
    4 7 13 10
    2
    4.000 4.000
    6.000 -4.000
    10 1 6 10
    1
    20.000 -0.500
    8 3 7 50
    5
    -0.750 1.207
    1.180 3.132
    27.111 -44.630
    -43.912 -22.104
    2.000 -6.000
    
    Expected output
    58
    0
    73