#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
  int n;
  scanf("%d", &n);
  int c, sum;
  while (n--) {
    scanf("%d%d", &c, &sum);
    LL res = sum % c;
    LL num = c - res;
    LL ans = 0;
    ans = res * ((sum + c - 1) / c) * ((sum + c - 1) / c) +
          num * (sum / c) * (sum / c);
    printf("%lld\n", ans);
  }
  return 0;
}
