#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int c, sum;
    scanf("%d %d", &c, &sum);
    if (sum % c == 0)
      cout << c * (sum / c * sum / c) << endl;
    else {
      int temp = sum / c;
      long long int total = (temp * temp) * c;
      int mod = sum % c;
      total += mod * ((temp + 1) * (temp + 1));
      total -= mod * (temp * temp);
      cout << total << endl;
    }
  }
}
