#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  while (n--) {
    long long a, b, c, d, j;
    cin >> a >> b;
    if (b % a == 0) {
      cout << (b / a) * (b / a) * a << endl;
    } else if (b % a != 0) {
      c = b / a;
      d = a - (b % a);
      cout << (c + 1) * (c + 1) * (b % a) + (b / a) * (b / a) * d << endl;
    }
  }
}
