#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll rooms;
  cin >> rooms;
  while (rooms--) {
    ll c, sum;
    cin >> c >> sum;
    if (sum % c == 0)
      cout << c * ((sum / c) * (sum / c)) << endl;
    else {
      ll temp = sum / c;
      ll total = (temp * temp) * c;
      ll res = sum % c;
      total += res * ((temp + 1) * (temp + 1));
      total -= res * (temp * temp);
      cout << total << endl;
    }
  }
}
