#include #include #include #include #include #include #include #include #include #include #include #include #include #include // #define _GLIBCXX_DEBUG // #define _LIBCPP_DEBUG 0 #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define revrep(i, n) for(int i = (int)(n - 1); i >= 0; --i) #define range(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define revrange(i, s, t) for(int i = (int)(t - 1); i >= (int)(s); --i) #define srange(i, s, t, step) for(int i = (int)(s); i < (int)(t); i+=int(step)) #define popcnt(x) __builtin_popcountll(x) #define wakarahen std::ios::sync_with_stdio(false);std::cin.tie(nullptr) using namespace std; using ll = long long; using pii = pair; using pll = pair; template inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } inline bool inside(int x, int y, int h, int w) { return (x >= 0 && x < h && y >= 0 && y < w); } int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1, 0}; const ll inf = 1e18; ll solve() { ll x, a; cin >> x >> a; ll ans = inf; range(i, 1, a + 1) { ll div = a / i; ll mod = a % i; ll tmp = mod * (div + 1) * (div + 1); tmp += (i - mod) * div * div; tmp += i * x; chmin(ans, tmp); } return ans; } int main() { int t; cin >> t; while (t--) { cout << solve() << endl; } }