Electrical Pollution

No attempts yetTime limit1sMemory limit128 MB

Problem

Sortonia is the capital of the North Nlogonia province. Almost all of its streets form a square grid aligned North–South or West–East. The only exception is Merge Avenue, which runs Southwest–Northeast, cutting city blocks along their diagonals.

Sortonia harnesses the Earth's magnetic field for energy: a power generator is installed at every intersection of Merge Avenue. Each generator produces an anomaly in the local magnetic field, represented by an integer value.

An anomaly propagates indefinitely in all four compass directions (North, South, West, East). A point that is not directly north, south, west, or east of a generator is unaffected by it. If a point is aligned with two generators, the anomaly there is the sum of the two anomalies.

For example, a point $R$ that lies exactly where a generator sits has an anomaly equal to that single generator's value, while a point $T$ that is aligned with the generator at $R$ and with the generator at another point $S$ has an anomaly equal to the sum of those two generators' values.

The biophysicists measured the anomaly at some intersections and want to predict the anomaly at others. Given the measurements, output the anomaly at each queried intersection when it is uniquely determined, and report that it is impossible otherwise.

Input

The input consists of several test cases. The first line of each test case contains two integers $M$ and $Q$: the number of measurements and the number of queries ($1 \le M, Q \le 10^4$).

Each of the next $M$ lines contains three integers $X$, $Y$ and $A$, meaning that the measured anomaly at point $(X, Y)$ is $A$ ($-10^7 \le X, Y \le 10^7$ and $-10^4 \le A \le 10^4$).

Each of the next $Q$ lines contains two integers $X'$ and $Y'$: the anomaly at point $(X', Y')$ must be predicted ($-10^7 \le X', Y' \le 10^7$).

All positions are measured in city blocks; the first coordinate increases from West to East and the second from South to North. Point $(0, 0)$ lies on Merge Avenue. Within a test case, no point is measured more than once and no point is queried more than once, and all measurements are consistent.

The last test case is followed by a line containing two zeros.

Output

For each test case output $Q + 1$ lines. On the $i$-th line, write the answer to the $i$-th query: if the measurements are enough to determine the anomaly at the queried point, write that integer; otherwise write a single asterisk *. After each test case, print a line containing a single hyphen -.