#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define T_T while(T--)
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=0x3f3f3f3f;
int a,b,c,l,r;
int js(int x){
return a*x*x+b*x+c;
}
/*void sanfen(double l,double r){
double mx,mi,m,mm;
double x=l,y=r;
while(r-l>=1e-6){
m=(l+r)/2.0;
mm=(m+r)/2.0;
if(js(m)>=js(mm))r=mm;
else l=m;
}
mx=js(l);
l=x;r=y;
while(r-l>=1e-6){
m=(l+r)/2.0;
mm=(m+r)/2.0;
if(js(m)<=js(mm))r=mm;
else l=m;
}
mi=js(l);
printf("%.0lf %.0lf\n",mx,mi);
}*/
int main(){
int T;
SI(T);
int mi,mx;
T_T{
scanf("%d%d%d%d%d",&a,&b,&c,&l,&r);
mi=INF;mx=-INF;
for(int i=l;i<=r;i++){
mi=min(mi,js(i));
mx=max(mx,js(i));
}
printf("%d %d\n",mx,mi);
}
return 0;
}
/*
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define T_T while(T--)
#define mem(x,y) memset(x,y,sizeof(x))
double a,b,c,l,r;
double js(double x){
return a*x*x+b*x+c;
}
int main(){
int T;
SI(T);
T_T{
scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&l,&r);
double mid=-b/(2*a);
double m[3];
m[0]=js(mid);
m[1]=js(l);m[2]=js(r);
//printf("%lf %lf %lf\n",m[0],m[1],m[2]);
if(l<=mid&&mid<=r)printf("%.0lf %.0lf\n",*max_element(m,m+3),*min_element(m,m+3));
else printf("%.0lf %.0lf\n",max(m[1],m[2]),min(m[1],m[2]));
}
return 0;
}*/