#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d = 0, e = 0, f = 0, g = 0, h[500001], i, j, k = 0, l = 0,
                     r = 0, p[500001], n[500001], m[500001], q, u, v, w, y, z;
  string s, t, x;
  cin >> a;
  for (i = 1; i <= a; i++) {
    cin >> b >> c;
    e = 0;
    d = c / b;
    if (c % b == 0) {
      for (j = 1; j <= b; j++) {
        e += d * d;
      }
      cout << e << endl;
    } else {
      for (j = 1; j <= c % b; j++) {
        e += (d + 1) * (d + 1);
      }
      for (j = j; j <= b; j++) {
        e += d * d;
      }
      cout << e << endl;
    }
  }
}
