This page is still under construction.

Parts of this page are still being built. What you see may change.

Schedule

Time limit2sMemory limit512 MB

Summary
Assign interval tasks to machines so no two overlapping tasks share a machine; minimize the number of machines, then the total working time (earliest start to latest finish) across those machines.
Level

Hard8 of 10

Topics
Intervals, Greedy, Sorting, Heap
Solved
No attempts yet

Problem

There are NN tasks: task ii has to start at moment sis_i and finish at moment eie_i. There is a potentially infinite supply of machines. We want to assign tasks to machines. Each task is assigned to one machine. A machine may handle any number of tasks as long as no two of them overlap. Tasks ii and jj are said to overlap if the intersection of the open intervals (si,ei)(s_i, e_i) and (sj,ej)(s_j, e_j) is non-empty.

A machine is turned on at the moment when the earliest of its assigned tasks has to start, and turned off at the moment when the latest of them has to finish. The working time of a machine is the length of the time period between these two moments: a single machine can be turned on and off only once.

Find the minimum possible number of machines KK such that we can perform all tasks using only KK machines. Also, when using KK machines, find the minimum possible sum of all their working times.

Input

The first line of input contains an integer TT, the number of test cases (1≤T≤1001 \le T \le 100).

Each test case begins with a line containing one integer NN (0<N≤1050 < N \le 10^5). Each of the next NN lines contains two integers sis_i and eie_i (0≤si<ei≤1090 \le s_i < e_i \le 10^9).

It is guaranteed that N>50N > 50 for no more than 10 test cases.

Output

For each test case, print two integers in one line: the minimum possible number of machines KK to perform all tasks and the minimum sum of all working times when using KK machines.

Examples1

  1. Example 1

    Input
    1
    3
    1 3
    4 6
    2 5
    
    Expected output
    2 8