#include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f #define mod 9999991 using namespace std; void fre(){freopen("d://input.txt","r",stdin);freopen("d://output.txt","w",stdout);} #define MS(x,y) memset(x,y,sizeof(x)) typedef __int64 LL; const int N=105; int s[N]; int main(){ int t,a,b,c,l,r; scanf("%d",&t); while(t--){ scanf("%d %d %d %d %d",&a,&b,&c,&l,&r); int maxx=-inf,minx=inf,x; for(int i=l;i<=r;i++){ x=a*i*i+b*i+c; maxx=max(maxx,x); minx=min(minx,x); } printf("%d %d\n",maxx,minx); } return 0; }