#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long c, sum;
    cin >> c >> sum;
    vector<long long> v(c);
    for (long long j = 0; j < c; j++) v[j] = sum / c;
    for (long long j = 0; j < sum % c; j++) v[j]++;
    long long ans = 0;
    for (long long j = 0; j < c; j++) ans += v[j] * v[j];
    cout << ans << '\n';
  }
  return 0;
}
