#include <bits/stdc++.h>
using namespace std;
long long z = 1000000000 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    long long n, ans = 0, i, j, p, l = 0, sum = 0, q = 0, r, cnt = 0, k, m = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> p >> q;
      if (p >= q) {
        cout << q << "\n";
      } else {
        l = q / p;
        r = q % p;
        ans = 0;
        if (r == 0) {
          for (j = 0; j < p; j++) {
            ans += (l * l);
          }
          cout << ans << "\n";
        } else {
          k = p - r;
          for (j = 0; j < k; j++) {
            ans += l * l;
          }
          for (j = 0; j < r; j++) {
            ans += (l + 1) * (l + 1);
          }
          cout << ans << "\n";
        }
      }
    }
  }
  return 0;
}
