#include #define INF 16843009 using namespace std; int n, m, i, j, k, a, b, c, l, r, t; double fun(double f) { double t = f*f*a + b*f + c; return t; } int main() { scanf("%d", &t); while (t--) { int max = -INF; int min = INF; scanf("%d%d%d%d%d", &a, &b, &c, &l, &r); for (int i = l; i <= r; i++) { double t=fun(i); if (max < t) { max = t; } if (min > t) { min = t; } } printf("%d %d\n", max, min); } return 0; }