Roundgod is a famous milk tea lover at Nanjing University second to none. This year, he plans to conduct a milk tea festival. There will be nn classes participating in this festival, where the iith class has aiai students and will make bibi cups of milk tea.
Roundgod wants more students to savor milk tea, so he stipulates that every student can taste at most one cup of milk tea. Moreover, a student can't drink a cup of milk tea made by his class. The problem is, what is the maximum number of students who can drink milk tea?
Input
The first line of input consists of a single integer TT(1≤T≤25)(1≤T≤25), denoting the number of test cases.
Each test case starts with a line of a single integer nn(1≤n≤106)(1≤n≤106), the number of classes. For the next nn lines, each containing two integers a,ba,b(0≤a,b≤109)(0≤a,b≤109), denoting the number of students of the class and the number of cups of milk tea made by this class, respectively.
It is guaranteed that the sum of nn over all test cases does not exceed 6×1066×106.
Output
For each test case, print the answer as a single integer in one line.