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