/** * @FileName a.cpp * @Author kanpurin * @Created 2022.01.07 23:50:18 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int t;cin >> t; for (int _ = 0; _ < t; _++) { ll n,m;cin >> n >> m; if (m == 1) { cout << 0 << endl; } else if (m <= n) { cout << (m-2)/2+1 << endl; } else { cout << (m-n-1)*(m-n+4)/2+((2*n-m)/2) << endl; } } return 0; }