beecrowd | 2632

Magic and Sword

By Edson Alves da Costa Júnior, UNB Brazil

Timelimit: 1

In the Magic and Sword Tower defense, the player can cast area spells to defeat the enemy units. The spells are elemental: fire, water, air and earth, and the affected region is determined by a circle whose radius depends on the level of the spell.

The table below lists each spell, damage and its radius per level:

The enemy units are delimited by a rectangle of width w and height h, with the lower left corner positioned at the point (x0, y0). The enemy will suffer damage if their bounding rectangle has any intercession with the area defined by the spell circle.

Given the position and the bounding rectangle of the enemy unit, the center of the explosion, the identifier and level of the spell, determine the damage to the unit. If the unit is out of the spell range, the damage is equal to zero.

Input

The input consists of T (1 ≤ T ≤ 1000) test cases, where the value of T is reported in the first line of the input. Each test case consists of two lines. The first contains four integers representing the dimensions w and h (1 ≤ w, h ≤ 1000) of the rectangle and the coordinates x0 and y0 (0 ≤ x0, y0 ≤ 1000) from the lower left corner. The second line of the test case contains a string with the spell identifier (fire, water, earth and air), the level N of this spell (1 ≤ N ≤ 3) and the coordinates cx e cy (0 ≤ cx, cy ≤ 1000) from the center of the explosion area.

Output

For each test case, the output must be the value of the damage received by the unit, followed by a line break.

 Input Sample Output Sample 4 10 10 50 50 fire 1 85 55 10 10 50 50 fire 2 85 55 10 10 50 100 water 3 100 100 10 10 50 100 air 3 100 100 0 200 300 100