#include #include #include #include #include using namespace std; const int maxn = 128; typedef long long LL; const LL inf=0x3f3f3f3f; int row,col; int mat[maxn][maxn]; int temp[maxn][maxn]; LL a,b,c,l,r; LL fun(LL x) { return a*x*x+b*x+c; } int main(void) { //freopen("1.txt","r",stdin); int t; scanf("%d",&t); while(t--) { scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&l,&r); LL minn=inf; LL maxx=-inf; for(int i=l; i<=r; ++i) { minn=min(fun(i),minn); maxx=max(fun(i),maxx); } printf("%lld %lld\n",maxx,minn); } return 0; }