#include <bits/stdc++.h>
#define F(i,j,k) for(int i=(j);i<=(k);++i)
#define D(i,j,k) for(int i=(j);i>=(k);--i)
#define rep(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();++it)
#define Rep(a,s) for(auto a:s)
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll quick_pow(ll x,ll y,ll Mod){
    ll res=1;
    while(y){
        if(y&1)res=res*x%Mod;
        x=x*x%Mod,y>>=1;
    }
    return res;
}
ll inv(ll x,ll Mod){return quick_pow(x,Mod-2,Mod);}
namespace IO{
    template <class T>
    inline void read(T &x){
        x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
        x*=f;
    }
};
using namespace IO;
const int N=500005;
int n;
ll a[N],ans;
priority_queue<ll,vector<ll>,greater<ll>>pq;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    #endif
    read(n);
    F(i,1,n*2)read(a[i]);
    D(i,n,1){
    	ll x=a[i],y=a[2*n-i+1];
    	if(x<y)swap(x,y);
    	pq.push(x);
    	if(pq.top()<y)pq.pop(),pq.push(y);
	}
	ll ans=0;
	while(!pq.empty())ans+=pq.top(),pq.pop();
	cout<<ans;
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

ll solve(ll L, ll R) {
  ll x = R - 2 * L + 1;
  if (x <= 0) {
    return 0;
  } else {
    return x * (x + 1) / 2;
  }
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int T;
  cin >> T;

  vector<ll> L(T);
  vector<ll> R(T);
  for (size_t i = 0; i < T; i++) {
    cin >> L[i] >> R[i];
  }

  // main procedure
  // output
  for (size_t i = 0; i < T; i++) {
    ll ans = solve(L[i], R[i]);
    cout << ans << endl;
  }

  return 0;
}