#include <bits/stdc++.h>
using namespace std;
int c, d, r, k, ans, n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c >> k;
    if (k <= c) {
      cout << k << '\n';
      continue;
    }
    r = k / c;
    ans = c * r * r;
    d = k % c;
    ans -= d * r * r;
    ans += d * (r + 1) * (r + 1);
    cout << ans << '\n';
  }
}
