#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int b, c;
    scanf("%d%d", &b, &c);
    if (c % b == 0) {
      int j = c / b;
      long long int ans = b * (j * j);
      printf("%lld\n", ans);
    } else {
      int k = c % b;
      int j = c / b;
      long long int ans = (j + 1) * (j + 1) * k;
      ans += (b - k) * j * j;
      printf("%lld\n", ans);
    }
  }
  return 0;
}
