#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int c, sum;
    cin >> c >> sum;
    if (sum < c)
      cout << sum << endl;
    else {
      int a = sum / c;
      int b = sum % c;
      int dif = c - b;
      int ans = dif * a * a;
      int z;
      if (b != 0)
        z = (sum - (dif * a)) / b;
      else
        z = 0;
      ans += b * (z * z);
      cout << ans << endl;
    }
  }
  return 0;
}
