#include <bits/stdc++.h>
using namespace std;
void solve() {
  int c, s;
  cin >> c >> s;
  int rem = s % c;
  int d = s / c;
  int ans = rem * (d + 1) * (d + 1) + (c - rem) * d * d;
  cout << ans << "\n";
}
void test() {}
int main() {
  test();
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
