#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a, b;
  unsigned long long int sum;
  cin >> n;
  while (n--) {
    sum = 0;
    cin >> a >> b;
    while (b != 0) {
      if (b % a == 0) {
        sum = sum + ((a * pow(b / a, 2)));
        cout << sum << endl;
        break;
      } else {
        sum = sum + pow((b / a), 2);
        b = b - (b / a);
        a--;
      }
      if (b == 0) {
        cout << sum << endl;
        break;
      }
    }
  }
}
