#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, sum;
    cin >> c >> sum;
    int base = sum / c;
    int res = sum - base * c;
    int rr = c - res;
    cout << 1ll * res * (base + 1) * (base + 1) + 1ll * rr * base * base
         << endl;
  }
  return 0;
}
