#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int c, sum;
    cin >> c >> sum;
    long long ans = 0;
    int temp = sum % c;
    sum /= c;
    if (temp != 0) ans += temp * (sum + 1) * (sum + 1);
    ans += (c - temp) * sum * sum;
    cout << ans << endl;
  }
  return 0;
}
