In a certain 2D kingdom, there exist beacons, numbered .
Since they were built at different times during the kingdom's history, they were not all constructed under the same specifications. As such, certain beacons may be brighter than others. A beacon 's range is defined as the radius around the beacon's location inside which the light from the beacon is visible.
Initially, all beacons are unlit. In the case of an invasion, a beacon will be lit, and the light from it will signal all beacons within its range (including beacons just barely within its range) to light as well. In this way, news of the invasion will propagate throughout the entire kingdom efficiently.
Or at least, that's what's supposed to happen. However, due to the haphazard way in which the beacon network was built, it may not function as intended. That is, some beacons or groups of beacons may be separated from each other, so that a signal may not be physically able propagate through the entire network.
As part of a repairing initiative, Ironwood has been tasked with answering queries of the form , — whether beacon will ever be lit when beacon is lit.
Subtask 1 [80%]
Subtask 2 [20%]
For all cases, and .
The first line of input will contain two space-separated integers and .
For the next lines, line will represent beacon , and will contain three space-separated positive integers: , , and . The value of these integers will not exceed .
Finally, the next lines will each contain two space-separated integers representing a query: and .
For each query, one line containing
YES if the two beacons are connected, or
2 2 1 1 5 4 1 1 1 2 2 1