#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
//#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 998244353;

ll sum(ll mn, ll mx) {
	return (mx - mn + 1)*(mn + mx) / 2;
}

int main() {
	int t, l, r;
	cin >> t;
	rep(i, t) {
		cin >> l >> r;
		int mx;
		mx = r - l - l + 1;
		mx = max(mx, 0);

		cout << sum(1, mx) << endl;
	}
}
/*
    author : Aryan Agarwal, IIT KGP
    created : 10-January-2021 18:43:37 IST
*/

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mxn = 2e5;
const long long INF = 2e18;
const int32_t M = 1000000007; /*more than 1e9 */ /*7 + 1e9*/
// const int32_t M = 998244353; /*less than 1e9 */   /*1 + 7*17*(1<<23) */
const long double pie = acos(-1);

#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

vector <int> mx(mxn,-INF);
vector <int> a(mxn);
vector< vector<int> > adj(mxn);
vector <bool> vis(mxn);
// vector <bool> ans(mxn,-INF);
int ans=-INF;
int n,m;

void dfs(int u){
    vis[u]=true;

    for(int to : adj[u])
    {
        if(!vis[to])dfs(to);
    }

    for(int to : adj[u])
    {
        mx[u]=max(mx[to],mx[u]);
        mx[u]=max(a[to],mx[u]);
    }

    ans=max(ans,-a[u]+mx[u]);
    // dbg(u,a[u],mx[u]);

}

void solve_LOG()
{
    cin>>n>>m;

    F(i,0,n-1)cin>>a[i];

    F(i,0,m-1)
    {
        int u,v;
        cin>>u>>v;
        --u;--v;
        adj[u].pb(v);
    }

    F(i,0,n-1)
    {
        if(!vis[i])
            dfs(i);
    }

    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    // defualt mxn_sieve = 1e5
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    // default [L,R] = [1,1e5]
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    // default mxn_fact = 1e5
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}