#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  while (n--) {
    long long ci, sum;
    cin >> ci >> sum;
    long long n = sum / ci;
    long long rem = sum % ci;
    long long ans = rem * (pow(n + 1, 2));
    ci -= rem;
    ans += ci * (pow(n, 2));
    cout << ans << "\n";
  }
  return 0;
}
