#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  long long int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long int c, sum;
    cin >> c >> sum;
    long long int x = sum / c, rem = sum % c;
    long long int ans = (c - rem) * x * x + rem * (x + 1) * (x + 1);
    cout << ans << endl;
  }
  return (0);
}
