#include #include #include #include #include #define eps 1e-6 using namespace std; int T,a,b,c,l,r; int maxx,minn; inline int Min(int a,int b) {return a>b?b:a;} inline int Max(int a,int b) {return a>b?a:b;} inline int F(int x) {return a*x*x+b*x+c;} int main() { scanf("%d",&T); for (int kase=1;kase<=T;kase++) { maxx=-10000000,minn=10000000; scanf("%d%d%d%d%d",&a,&b,&c,&l,&r); for (int j=l;j<=r;j++) { maxx=Max(maxx,F(j)); minn=Min(minn,F(j)); } printf("%d %d\n",maxx,minn); } return 0; }