#include <bits/stdc++.h>
using namespace std;
long long ar[10001];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, ans = 0;
    cin >> a >> b;
    if (b > a) {
      memset(ar, 0, sizeof ar);
    } else {
      ans = b;
      cout << ans << endl;
      continue;
    }
    while (b) {
      if (b <= a) {
        ar[1]++;
        ar[b + 1]--;
        b = 0;
        break;
      }
      ar[1]++;
      ar[a + 1]--;
      b -= a;
    }
    for (int i = 1; i <= a; i++) ar[i] += ar[i - 1];
    for (int i = 1; i <= a; i++) ans += ar[i] * ar[i];
    cout << ans << endl;
  }
  return 0;
}
