#include using namespace std; using int64 = long long; bool IsLess(const int a, const int b, const int c, const int d) { return (int64)a * d < (int64)b * c; } vector ContinuedFraction(int p, int q) { vector r; while (q) { const int x = p / q; r.push_back(x); tie(p, q) = make_tuple(q, p - x * q); } return r; } pair, vector> GetRepresentations(const vector& r) { vector oth = r; --oth.back(); oth.push_back(1); return make_pair(r, oth); } pair GetFraction(const vector& l, const vector& r) { vector t; { int i = 0; while (i < (int)l.size() and i < (int)r.size() and l[i] == r[i]) { t.push_back(l[i]); ++i; } if (i < (int)l.size() and i < (int)r.size()) { t.push_back(min(l[i], r[i]) + 1); } else if (i < (int)l.size()) { t.push_back(l[i] + 1); } else { t.push_back(r[i] + 1); } } int a = t.back(), b = 1; for (int i = (int)t.size() - 2; i >= 0; --i) { // x + b / a int64 x = (int64)t[i] * a + b; int64 d = __gcd(x, a); b = a / d; a = x / d; } return make_pair(a, b); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int num_tests; cin >> num_tests; int sum_n = 0; while (num_tests--> 0) { int n, x, y; cin >> n >> x >> y; sum_n += n; assert(sum_n <= 1000000); long long sum_v = 0; int num_a = 0, num_b = 0; int bx = 0, by = 1; for (int i = 0; i < n; ++i) { int x; cin >> x; sum_v += x; assert(1 <= x and x <= 1000000000); ((i % 2) ? num_b : num_a) += x; if (i != n - 1 and IsLess(bx, by, num_b, num_a)) { bx = num_b; by = num_a; } } assert(sum_v <= 1000000000); if (num_a == 0 or num_b == 0 or n % 2 == 1) { cout << -1 << endl; continue; } // look for a nice fraction in // (bx/by, num_b/num_a) if (not IsLess(bx, by, num_b, num_a)) { cout << -1 << endl; continue; } auto l = GetRepresentations(ContinuedFraction(bx, by)), r = GetRepresentations(ContinuedFraction(num_b, num_a)); for (auto r : {GetFraction(l.first, r.first), GetFraction(l.first, r.second), GetFraction(l.second, r.first), GetFraction(l.second, r.second)}) { int a, b; tie(a, b) = r; if (IsLess(bx, by, a, b) and IsLess(a, b, num_b, num_a) and a <= x and b <= y) { cout << a << ' ' << b << endl; goto next_iter; } } cout << -1 << endl; next_iter:; } return 0; }