#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int ans[10005];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int c, sum;
    cin >> c >> sum;
    memset(ans, 0, sizeof(ans));
    for (int i = 1, cnt = 0; i <= sum; i++, cnt++) {
      ans[cnt % c]++;
    }
    long long res = 0;
    for (int i = 0; i < c; i++) {
      res += ans[i] * ans[i];
    }
    cout << res << endl;
  }
}
