#include #include #include using namespace std; typedef long long llong; llong eval(llong b,llong c,llong x) { return x*x + b*x + c; } llong getSmallerOrEq(llong b,llong c,llong s,llong v) { if (4LL * (c - v) > b*b) return 0LL; long double cs= sqrt( (long double)( b*b - 4LL * (c - v) ) ); llong approx = (-b + (llong)cs)/2LL; while(eval(b,c,approx) <= v) approx++; while(eval(b,c,approx) > v) approx--; if (approx < s) return 0; return approx - s + 1; } int main() { freopen("sequences.in","r",stdin); freopen("sequences.out","w",stdout); int q; int i; scanf("%d",&q); for (i=1;i<=q;i++) { llong b1,c1,s1; llong b2,c2,s2; llong n; llong l = -4000000000000000000, r = 4000000000000000000; llong mid,best; scanf("%lld %lld %lld %lld %lld %lld %lld",&b1,&c1,&s1,&b2,&c2,&s2,&n); while(l <= r) { mid = (l + r) / 2LL; llong cnt = getSmallerOrEq(b1, c1, s1, mid) + getSmallerOrEq(b2, c2, s2, mid); if (cnt >= n) { best = mid; r = mid - 1LL; } else { l = mid + 1LL; } } printf("%lld\n",best); } return 0; }