#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long x, y, z;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    long long ans = 0;
    scanf("%lld%lld", &x, &y);
    if (x >= y) {
      ans += y;
      printf("%lld\n", ans);
      continue;
    }
    long long d = (y - 1) / x + 1;
    z = x * d - y;
    ans += z * (d - 1) * (d - 1) + (x - z) * d * d;
    printf("%lld\n", ans);
  }
}
