#ABC474E. 一次性优惠券 / One Time Coupon

一次性优惠券 / One Time Coupon

Problem Statement

A certain shop sells NN types of products. Each product can be purchased any number of times.

The ii-th type of product (1iN)(1\le i\le N) can be bought in the following two ways:

  • Buy it for AiA_i yen without using a coupon, and receive one coupon.
  • Use one coupon and buy it for BiB_i yen.

Initially, you have no coupons.

Find the minimum amount of money required to buy every product at least once.

You are given TT test cases; solve each of them.

Constraints

  • 1T2×1051\le T\le 2\times 10^5
  • 1N2×1051\le N\le 2\times 10^5
  • 1Bi<Ai1091\le B_i < A_i \le 10^9
  • The sum of NN over all test cases is at most 2×1052\times 10^5.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • TT
  • case1\text{case}_1
  • case2\text{case}_2
  • \vdots
  • caseT\text{case}_T

Each test case is given in the following format:

  • NN
  • A1A_1 B1B_1
  • A2A_2 B2B_2
  • \vdots
  • ANA_N BNB_N

Output

Output the answers for the test cases in order, separated by newlines.

3
5
11 6
6 5
2 1
8 3
7 4
4
5 1
5 2
5 3
5 4
6
24 13
24 2
50 12
35 25
28 26
10 1
23
13
100

Consider the first test case.

For example, by acting as follows, you can buy every product at least once for 2323 yen:

  • Buy the second type of product for 66 yen without using a coupon. You now have 11 coupon.
  • Buy the third type of product for 22 yen without using a coupon. You now have 22 coupons.
  • Buy the third type of product for 22 yen without using a coupon. You now have 33 coupons.
  • Use a coupon to buy the first type of product for 66 yen. You now have 22 coupons.
  • Use a coupon to buy the fourth type of product for 33 yen. You now have 11 coupon.
  • Use a coupon to buy the fifth type of product for 44 yen. You now have 00 coupons.

It is impossible to buy every product at least once for less than 2323 yen, so output 2323 on the first line.