#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 123;
const long long infl = (long long)1e18 + 123;
const long long INF = (1LL << 60) - 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    int x;
    if (a > b)
      x = a - b;
    else if (a < b)
      x = b - a;
    else
      return 0;
    int m = x / 2;
    int n = x - m;
    cout << (n * (n + 1)) / 2 + (m * (m + 1)) / 2;
    cout << '\n';
  }
  return 0;
}
