#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int c, sum;
    cin >> c >> sum;
    int temp1 = sum / c, temp2 = sum % c;
    long long res = 0;
    for (int j = 1; j <= c; j++) {
      if (temp2 > 0)
        res += (temp1 + 1) * (temp1 + 1), temp2--;
      else
        res += temp1 * temp1;
    }
    cout << res << '\n';
  }
}
