#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    long long c, sum;
    cin >> c >> sum;
    long long d = sum / c;
    long long r = sum - d * c;
    cout << c * d * d + r * (2 * d + 1) << endl;
  }
}
