#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int N;
	int maxA; int minB;
	cin >> N;
	vector<int>A(N); vector<int>B(N);

	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	for (int i = 0; i < N; i++) {
		cin >> B.at(i);
	}
	 maxA = *max_element(A.begin(),A.end());
	 minB = *min_element(B.begin(), B.end());
	
	 if (minB-maxA+1 <= 0) {
		 cout << 0 << endl;
	 }
	 else if(minB-maxA+1>0){
		 cout << -maxA + minB + 1 << endl;
	 }
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double lxd;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;

#define mem(dp, a) memset(dp, a, sizeof dp)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repb(i, a, b) for (ll i = a; i >= b; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define fo(i, n, x) for (ll i = x; i <= n; i++)
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define make_graph(a, b) \
    adj[a].pb(b);        \
    adj[b].pb(a)
#define tr(c, it) for (((c).begin())it = (c).begin(); it != (c).end(); it++)
#define test   \
    ll tt;     \
    cin >> tt; \
    label:     \
    while (tt--)
#define fls fflush(stdout)
#define F first
#define S second
#define all(arr) arr.begin(), arr.end()
#define read(arr, n) f(i, n) cin >> arr[i]
#define INT_BITS 32

const ll mod = 1000000007;
const ll inf = 2e9 ;
const ll MAXN = 2e5 + 1;


main(){
    test{
        ll a, b ;
        cin >> a >> b ;
        
        if(b < 2*a){
            cout << "0\n" ; goto label ;
        }
        
        ll ans = max(0ll, b - (2*a)) + 1 ;
        
        cout << (ans * (ans + 1)) / 2 << "\n" ;
        
    }
    
}