#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;
using Graph = vvi;

typedef pair<int,int> P;
ll INF = 1000000000000;
ll MOD = 998244353;

int  gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }



int main(){
    int T;
    cin >>T;
    rep(i,T){
        ll L,R;
        cin >>L>>R;
        if(2*L<=R){
            cout <<(R-2*L+1)*(R-2*L+2)/2<<endl;
        }
        else cout<<0<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{

    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    rep2(i, 4, 4 * n + 1)
    {
        if ((k + i) % 2 == 0)
        {

            ll e = (k + i) / 2;
            ll f = i - e;
            if (e > 1 && f > 1)
            {
                ll e2 = 0;
                ll f2 = 0;
                if (n * 2 < e)
                {
                    e = 0;
                }
                else if (e <= n)
                {
                    e = e - 1;
                }
                else
                {
                    e = 2 * n - e + 1;
                }
                if (n * 2 < f)
                {
                    f = 0;
                }
                else if (f <= n)
                {
                    f = f - 1;
                }
                else
                {
                    f = 2 * n - f + 1;
                }
                ans += e * f;
            }
        }
    }
    cout << ans << endl;
}