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