Wire Connection

No attempts yetTime limit1sMemory limit128 MB

Problem

A digital logic circuit on a printed circuit board (PCB) is a collection of interconnected parts, usually integrated circuit (IC) chips. Each IC chip has several pins that must be connected by wires to pins on other chips or to a power line. Most PCBs are built as a stack of layers. The wiring pattern in each layer consists of horizontal and vertical wires. In a multilayer board, layers are joined by drilled holes called vias, which form conductive paths between layers.

When designing a complex PCB, one special layer is reserved for the power supply. That layer has the following properties.

  1. A single horizontal power line runs along the bottom of the layer.
  2. A set of horizontal wires is fixed in advance.
  3. Several vias are placed on the layer.
  4. Every horizontal wire must be connected to the power line by vertical wires. Each vertical wire starts at the power line, rises while crossing (and powering) some horizontal wires, and stops at a via.

To keep the design cost effective, we want to minimize the number of vertical wires attached to the power line on this layer.

A vertical wire placed at a via (s,t)(s, t) runs from the power line up to that via. It therefore powers exactly the horizontal wires (p,q,r)(p, q, r) with qsrq \le s \le r and p<tp < t.

In figure (a) there are four horizontal wires and seven vias. The minimum number of vertical wires needed to power every horizontal wire is three. Figure (b) shows one layout that uses three vertical wires. Note that a single horizontal wire may be crossed by more than one vertical wire.

(a)

(b)

Given the horizontal wires and the vias, compute the minimum number of vertical wires that connect the power line to all horizontal wires.

Input

The first line contains the number of test cases TT.

Each test case begins with a line containing two integers MM and NN (1M,N1001 \le M, N \le 100), where MM is the number of horizontal wires and NN is the number of vias.

Each of the next MM lines describes one horizontal wire with three integers pp, qq, rr, where pp (1p100001 \le p \le 10000) is the yy-coordinate of the wire and qq, rr (1q<r100001 \le q < r \le 10000) are the xx-coordinates of its left and right end points. No two horizontal wires intersect.

Each of the following NN lines describes one via with two integers ss, tt (1s,t100001 \le s, t \le 10000), which are the xx- and yy-coordinates of the via, respectively. At most one via lies on any vertical line, and no via lies on a horizontal wire. The power line lies on the xx-axis.

Output

For each test case, print a single line containing the minimum number of vertical wires that connect the power line to every horizontal wire. If it is impossible to connect every horizontal wire with at least one vertical wire, print IMPOSSIBLE instead.