#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int c, s;
    cin >> c >> s;
    if (s > c) {
      int q = s / c;
      cout << 1LL * q * q * (c - s % c) + (s % c) * (q + 1) * (q + 1) << endl;
    } else
      cout << s << endl;
  }
  return 0;
}
