for _ in range(int(input())):
n=int(input())
ans=int();B=0
for i in range(n):
a,b=map(int,input().split())
ans+=min(a,b)
B=max(B,max(a,b))
ans+=B;ans*=2
print(ans)
#include <bits/stdc++.h>
using namespace std;
#define enl '\n'
#define int long long
#define sz(s) (int)s.size()
#define all(v) (v).begin(),(v).end()
mt19937 rng (chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename A, typename B> ostream& operator<< (ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; }
template <typename A, typename B> istream& operator>> (istream& cin, pair<A, B> &p) {cin >> p.first; return cin >> p.second;}
template <typename A> ostream& operator<< (ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}
template <typename A> istream& operator>> (istream& cin, vector<A> &x){for(int i = 0; i < x.size()-1; i++) cin >> x[i]; return cin >> x[x.size()-1];}
template <typename A, typename B> A amax (A &a, B b){ if (b > a) a = b ; return a; }
template <typename A, typename B> A amin (A &a, B b){ if (b < a) a = b ; return a; }
const long long mod = 1e9+7;
const long long inf = 1e18;
void solve() {
int n;
cin>>n;
int h = 0,v = 0;
for(int i=0;i<n;i++) {
int a,b;
cin>>a>>b;
if(a > b) swap(a,b);
h += a;
amax(v,b);
}
cout<<2*(h+v)<<enl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int testcases = 1;
cin>>testcases;
while(testcases--) solve();
return 0;
}
1277C - As Simple as One and Two | 1301A - Three Strings |
460A - Vasya and Socks | 1624C - Division by Two and Permutation |
1288A - Deadline | 1617A - Forbidden Subsequence |
914A - Perfect Squares | 873D - Merge Sort |
1251A - Broken Keyboard | 463B - Caisa and Pylons |
584A - Olesya and Rodion | 799A - Carrot Cakes |
1569B - Chess Tournament | 1047B - Cover Points |
1381B - Unmerge | 1256A - Payment Without Change |
908B - New Year and Buggy Bot | 979A - Pizza Pizza Pizza |
731A - Night at the Museum | 742A - Arpa’s hard exam and Mehrdad’s naive cheat |
1492A - Three swimmers | 1360E - Polygon |
1517D - Explorer Space | 1230B - Ania and Minimizing |
1201A - Important Exam | 676A - Nicholas and Permutation |
431A - Black Square | 474B - Worms |
987B - High School Become Human | 1223A - CME |