#include <bits/stdc++.h>
using namespace std;
const int MN = 3e5 + 5;
const double P = 998244353;
inline void solve() {
  int c, s;
  scanf("%d%d", &c, &s);
  int k1 = s / c, k2 = s / c + (s % c != 0);
  long long c1 = c - s % c, c2 = s % c;
  printf("%lld\n", k1 * k1 * c1 + k2 * k2 * c2);
}
int main(int argc, char** argv) {
  int _;
  scanf("%d", &_);
  for (int i = 0; i < _; ++i) solve();
  return 0;
}
