#include <bits/stdc++.h>
using namespace std;
int64_t n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int64_t i = 0; i < n; i++) {
    int64_t c, sum;
    cin >> c >> sum;
    if (sum <= c) {
      printf("%" PRId64 "\n", sum);
    } else {
      int64_t per_rad = sum / c;
      int64_t extra = sum % c;
      int64_t normal = c - extra;
      int64_t total = 0;
      for (int64_t i = 0; i < normal; i++) {
        total += per_rad * per_rad;
      }
      for (int64_t i = 0; i < extra; i++) {
        total += (per_rad + 1) * (per_rad + 1);
      }
      printf("%" PRId64 "\n", total);
    }
  }
}
