func_code_string: #include <bits/stdc++.h>   using namespace std;   int tc = 0;   long long a, b, c, d;   inline long long sum(long long i) {     return -a * i + b * (d - 1) * i + i * (i - 1) / 2 * b * d;   }   inline long long calc(long long i) {     if (i < 0) return 0;     long long ans = 0;     if (i < (c + 1) / d) {       ans = min(ans, sum(i) - a + i * b);     } else {       i = (c + 1) / d;       ans = min(ans, sum(i) - a + (i - 1) * b + (c + 1 % d > 0) * b);       ans = min(ans, sum(i));       ans = min(ans, -a);     }     return ans;   }   inline void solve() {     ++tc;     scanf( %lld%lld%lld%lld , &a, &b, &c, &d);     if (c < d) {       if (b * c >= a)         printf( %lld n , a);       else         puts( -1 );     } else {       long long i = floor(-(-a + b * (d - 1) + b - 1.0 * b * d / 2) / (b * d));       i = max(i, 0ll);       long long dmg =           (-a + b * (d - 1) + b * d * ((c + 1) / d - 1) + ((c + 1) % d) * b);       long long ans = 0;       if (dmg < 0) {         puts( -1 );       } else {         ans = min(ans, calc(i - 1));         ans = min(ans, calc(i));         ans = min(ans, calc(i + 1));         ans = min(ans, calc(i + 2));         printf( %lld n , -ans);       }     }     return;   }   int main() {     int T;     for (scanf( %d , &T); T--; solve())       ;     return 0;   }   