#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
template <typename T>
bool lesser(T &a, T &b) {
  return a > b;
}
template <typename T>
bool better(T &a, T &b) {
  return a < b;
}
template <typename T>
class problem {
 public:
  typedef bool (*u)(T &, T &);
  vector<T> a;
  void insertvectorT(int n, u fff, int is) {
    for (int i = 0; i < n; i++) {
      T as;
      cin >> as;
      a.push_back(as);
    }
    if (is) sort(a.begin(), a.end(), fff);
  }
  void showvectorT(int be, int ed) {
    auto beg = a.begin() + be;
    auto del = a.begin() + ed;
    if (del >= a.end()) {
      del = a.end() - 1;
    }
    for (; beg <= del; beg++) cout << *beg << ' ';
    cout << endl;
  }
};
template <typename T>
using ss = bool (problem<T>::*)(T &, T &);
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long def = b / a;
    long long ret = b % a;
    cout << ret * (def + 1) * (def + 1) + (a - ret) * (def) * (def) << endl;
  }
}
