Nested Dolls

No attempts yetTime limit1sMemory limit128 MB

Problem

Dilworth is the world's most prominent collector of Russian nested dolls (matryoshkas): he owns thousands of them. These are the wooden, hollow dolls of different sizes, where the smallest doll sits inside the second-smallest, which in turn sits inside the next one, and so on.

One day he wonders whether there is a different way to nest them that leaves him with fewer separate nested dolls, which would make his collection even more magnificent.

He unpacks every doll and measures the width and height of each one. A doll with width $w_1$ and height $h_1$ fits inside another doll with width $w_2$ and height $h_2$ if and only if $w_1 < w_2$ and $h_1 < h_2$. Each doll can directly contain at most one other doll (which may itself contain another), so the dolls in a single nested set form a chain that is strictly increasing in both width and height.

Given all the measurements, compute the smallest number of separate nested dolls (sets) into which the entire collection can be assembled.

Input

The first line contains a single integer $t$ ($1 \le t \le 20$), the number of test cases.

Each test case begins with a line containing a single integer $m$ ($1 \le m \le 20000$), the number of dolls. It is followed by $2m$ integers $w_1, h_1, w_2, h_2, \ldots, w_m, h_m$, where $w_i$ is the width and $h_i$ is the height of doll $i$ ($1 \le w_i, h_i \le 10000$). These $2m$ integers may be split across one or more lines and are separated by whitespace.

Output

For each test case, output a single line containing the minimum number of separate nested dolls (sets) needed to hold the entire collection.