Ground Defense

Handle updates that add an arithmetic sequence of troops along a line of cities in one direction, and answer queries for a city's running total.

Medium6Prefix sumImplementationMathArrayNo attempts yetTime limit2sMemory limit512 MB

Problem

You are a denizen of Linetopia, whose nn major cities are equally spaced along an east-west line. They are numbered in order from 11 to nn, where 11 is the westmost city and nn is the eastmost city. Linetopia was a lovely place to live until forces from neighboring Trapez invaded. As part of Linetopia's citizen protection initiative, you have been asked to process information about Trapezoid troop movements, so that the government can determine which cities have been hit hardest and where to send reinforcements.

Linetopia intelligence has discovered that the Trapezoid forces attack in the following pattern. They send massive aircraft to drop troops on Linetopia's cities. Each aircraft starts at some city ii and drops ss soldiers there. The aircraft then flies either east or west. Each time it flies over another city, it drops aa more soldiers than it dropped on the previous city it passed. After performing dd drops, the aircraft returns to Trapez to resupply.

You receive intel updates that give the specs of each Trapezoid aircraft passing over Linetopia. You must also answer queries that ask how many Trapezoid troops have been dropped on a particular city so far.

Input

The first line contains a single integer TT (1T101 \le T \le 10), the number of test cases. The first line of each test case contains two integers: mm (1m100001 \le m \le 10\,000), the total number of updates and queries, and nn (1n5000001 \le n \le 500\,000), the number of cities in Linetopia.

Each of the next mm lines is either an update or a query. An update line begins with a capital U, followed by a capital E (east) or W (west) that gives the direction, followed by four integers ii (1in1 \le i \le n), ss (1s100001 \le s \le 10\,000), aa (0a100000 \le a \le 10\,000), and dd (1dn1 \le d \le n). These are the starting city, the number of soldiers in the first drop, the increase in soldiers per city, and the number of drops, respectively. An aircraft never flies west of city 11 or east of city nn during its dd drops.

A query line begins with a capital Q, followed by a single integer ii (1in1 \le i \le n), the city being queried.

Output

For each query, in input order, print one line with the number of Trapezoid troops dropped on that city up to that point.

Hint

In the sample, two aircraft fly over Linetopia. The first starts at city 11 and heads east. It drops 55 soldiers on city 11, 77 soldiers on city 22, and 99 soldiers on city 33. The second starts at city 33 and flies west. It drops 1010 soldiers on city 33 and 2020 soldiers on city 22.