#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 7;
int n;
int sum[maxn], c[maxn];
int main(int argc, char* argv[]) {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      cin >> c[i] >> sum[i];
    }
    for (int i = 1; i <= n; i++) {
      int t1 = sum[i] / c[i];
      int t2 = sum[i] - t1 * c[i];
      int cost = (c[i] - t2) * t1 * t1 + t2 * (t1 + 1) * (t1 + 1);
      cout << cost << endl;
    }
  }
  return 0;
}
