#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  while (n--) {
    int c, sum;
    cin >> c >> sum;
    long long ans = 0;
    long long key = sum / c;
    long long temp = sum - key * c;
    ans = c * key * key + 2 * temp * key + temp;
    cout << ans << endl;
  }
}
