#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    long long cost = (a - (b % a)) * (b / a) * (b / a);
    cost += (b % a) * ((b + a - 1) / a) * ((b + a - 1) / a);
    cout << cost << "\n";
  }
  return 0;
}
