#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n;
  cin >> n;
  while (n--) {
    long long a, b;
    cin >> a >> b;
    if (a >= b) {
      cout << b << "\n";
      continue;
    }
    long long val = b / a;
    long long val2 = b % a;
    cout << (a - val2) * val * val + (val2) * (val + 1) * (val + 1) << "\n";
  }
  return 0;
}
