#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#define IN
#define LL long long
#define P(t1) ((t1 - 1) / blk + 1)
using namespace std;

const int MAXN = 2e3 + 5;
int T;
LL A, B, C;

int main() {
	int i,j,k;
	scanf ("%d", &T);
	while (T--) {
		scanf ("%lld%lld", &A, &B), C = max (B - 2ll * A + 1, 0ll);
		printf ("%lld\n", (C + 1) * C / 2);
	}
	return 0;
}
#include <bits/stdc++.h>

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n = scan();
  vector<int64_t> a(n), b(n);
  generate(ALL(a), scan<>);
  generate(ALL(b), scan<>);
  int64_t ans = 0, mx = 0;
  for (int i : Rep(n)) {
    chmax(mx, a[i]);
    chmax(ans, mx * b[i]);
    cout << ans << '\n';
  }
}
