#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    if (a >= b)
      cout << b << endl;
    else {
      int yu_shu = b % a;
      b -= yu_shu;
      int chu = b / a;
      long long res = 0;
      for (int i = 0; i < (a - yu_shu); i++) res += chu * chu;
      for (int i = 0; i < yu_shu; i++) res += (chu + 1) * (chu + 1);
      cout << res << endl;
    }
  }
  return 0;
}
