#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c, sum;
  long long ans;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ans = 0;
    cin >> c >> sum;
    if (c > sum)
      ans = sum;
    else {
      int k = sum / c;
      int rem = sum % c;
      ans = (c - rem) * k * k;
      ans += rem * pow((k + 1), 2);
    }
    cout << ans << endl;
  }
  return 0;
}
