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