LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search Functions
Binary Numbers
Binary NumbersNumbers in codeBitwise Operations
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of Eratosthenes
Data Structures
StringsStackQueue
Dynamic Programming
About DPDP problems

The Crowded Pool

MediumProblem #33
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

A visitor who leaves at some moment is not at the pool in that moment.

People came and went from a swimming pool all day, and for every visitor the arrival time and the departure time are known. A visitor is at the pool during the period [a,b): they are there at the moment of their arrival a, and are not there at the moment of their departure b. Your task is to determine the largest number of people that were at the pool at the same moment.

Input

First line of input will be a single integer t - the number of testcases.
Each testcase starts with a line containing an integer n - the number of visitors, followed by n lines with two integers a and b each - one visitor's arrival and departure time.

Output

For every testcase print a single line with the largest number of visitors present at the same moment.

Example

Input
1
8
3 7
7 8
2 5
6 8
4 6
1 6
4 5
1 2
Output
5

At moment 4 the visitors with periods [3,7), [2,5), [4,6), [1,6) and [4,5) are all at the pool - five of them.

Constraints

1≤t≤1000
1≤n≤2⋅105
0≤a<b≤109
n1​+n2​+…+nt​≤2⋅105


This problem was adapted, with permission, from Najbrojniji presek intervala, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit