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