Wooden Sticks

No attempts yetTime limit1sMemory limit128 MB

Problem

A woodworking shop has nn wooden sticks. Each stick has a fixed length and weight. The sticks are processed by a machine one at a time. Before processing a stick, the machine may need some time to be prepared for that stick — this is called the setup time. The setup time is determined by the following rules.

  1. Processing the very first stick requires a setup time of 1 minute.
  2. Suppose a stick of length ll and weight ww has just been processed, and the next stick to process has length ll' and weight ww'. If lll \le l' and www \le w', then no setup time is needed. Otherwise the machine must change its tool, so a setup time of 1 minute is required.

You may process the sticks in any order. Find the minimum total setup time needed to process all of the sticks.

For example, suppose there are five sticks (4,9),(5,2),(2,1),(3,5),(1,4)(4,9), (5,2), (2,1), (3,5), (1,4). Processing them in the order (1,4),(3,5),(4,9),(2,1),(5,2)(1,4), (3,5), (4,9), (2,1), (5,2) needs a total setup time of 2 minutes, and this cannot be reduced any further, so the answer is 2.

Input

The first line contains the number of test cases TT.

Each test case consists of two lines. The first line contains the number of sticks nn (1n50001 \le n \le 5000). The second line contains l1 w1 l2 w2  ln wnl_1\ w_1\ l_2\ w_2\ \dots\ l_n\ w_n separated by spaces, where lil_i and wiw_i are the length and weight of the ii-th stick. All of these values are integers not greater than 1000010000.

Output

For each test case, print the minimum required setup time on its own line.