#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
void solve() {
  int c, s;
  cin >> c >> s;
  vector<int> a(c, 0);
  int rem = 0;
  for (int i = 0; i < c; ++i) {
    a[i] = s / c;
    rem += s / c;
  }
  rem = s - rem;
  int ctr = 0;
  while (rem--) {
    a[ctr % c]++;
    ctr++;
  }
  int ans = 0;
  for (int i = 0; i < c; ++i) {
    ans += a[i] * a[i];
  }
  cout << ans << '\n';
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
