#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    int t = b % a;
    int ans =
        ((a - t) * (b / a) * (b / a)) + (t) * ((b / a) + 1) * ((b / a) + 1);
    cout << ans << endl;
  }
}
