JUICE - Juice Extractor

Jerry loses himself in the interesting game: Fruit Ninja. Fruit Ninja is a game of iPhone and iPad in which the players cut the fruits coming from the bottom of the screen and gain the bonus from cutting more than two fruits with a single slice. Once a fruit is cut, it breaks into small pieces and cannot be cut any more.

After months of training, he becomes pro of this game. Actually, he can cut all the fruits on the screen at any time. Jerry also has a bad habit that he has no willing to leave some fruits for the future cutting. In the other words, after Jerry cuts the fruits, all the fruits on the screen breaks and no one left. That is why all his friends call him Juice Extractor.

Now he only consider about the bonus, when he cuts more than two fruits, he can gain some bonus scores as same as the number of fruits he slice at that time. For example, if Jerry cuts 4 fruits with a single slice, he can get 4 scores from this slice.

After Jerry gets the fruit schedule, he knows the appearing time and the disappearing time for every single fruit. He can only cut a fruit into pieces between its appearing time and disappearing time inclusive. He wants to know the maximum possible bonus scores he can receive.

Input

There are several test cases; the first line of the input contains a single integer T, denoting the number of the test cases. (T <= 200)

For each test case, the first line contains an integer N, denoting the total number of fruits. (1 <= N <= 1000)

The next N lines, each line describe a fruit. For each line, there are two integers Xi and Yi, where Xi is the appearing time of the fruit and Yi is the disappearing time of this fruit. (0 <= Xi <= Yi <= 1000000000)

Output

For each test case, output a single integer denoting the maximum scores that Jerry could possibly gain. See the sample for further details.

Example

Input:
1
10
1 10
2 11
3 12
4 13
13 14
14 15
13 19
20 22
21 23
22 24

Output:
Case #1: 10

Added by:Fudan University Problem Setters
Date:2011-05-10
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Fudan University Local Contest #2, by g201513

hide comments
2018-07-12 18:23:34 Manu
what will be the output for below case. 9 or 10
1
10
4 4
4 5
4 13
10 12
10 14
10 15
10 16
10 20
11 19
17 18
2014-12-11 15:04:40 T R Sriram
"when he cuts more than two fruits" not more than one :/ Costed me 2 WAs
2014-06-18 13:35:40 adijimmy
@[Trichromatic] XilinX :can u provide some more test cases getting wa :(

Last edit: 2014-06-18 13:36:15
2013-03-25 14:29:41 Aditya Muraletharan
Curious. Has anyone solved this in better than quadratic time?
2013-02-25 04:29:44 Ravu Sairam
How the answer is 10? Basically, the problem is to find the maximum number of overlapping intervals? In this case it is 4 right?
2013-01-13 14:51:34 foram
stuck!! What should be the state space? It cant be bit masking as then very large space will be required. Please give a hint.

Edit : my bad! "Jerry also has a bad habit that he has no willing to leave some fruits for the future cutting"

Last edit: 2013-02-01 06:10:15
2012-04-21 18:06:44 Rocker3011
can you provide some test cases? i believe this is not that easy :D

Last edit: 2012-04-21 18:07:11
2012-03-06 02:47:51 Brian Curcio
Can the fruit be cut at the disapearing time?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.