#include #include #include #include #include #include #include using namespace std; ifstream inF("apartments.in"); ofstream outF("apartments.out"); #define cin inF #define cout outF const int MAX_N = 200001; typedef unsigned long long ull; typedef long long sll; sll m, l, a1, a2, b1, b2; sll years; sll sell1, sell2; void input() { cin >> m >> l >> a1 >> a2 >> b1 >> b2; } void output() { cout << years << " " << sell1 << " " << sell2 << "\n"; } void bruteforce(sll year, sll s1, sll s2, sll money) { if (year > years) { years = year; sell1 = s1; sell2 = s2; } if (year == 4) return; ++year; if (s1 == -1) money += a1; if (s2 == -1) money += a2; money -= l; if (money >= 0) { bruteforce(year, s1, s2, money); } else { if (s1 == -1 && money + b1 >= 0) bruteforce(year, year, s2, money + b1); if (s2 == -1 && money + b2 >= 0) bruteforce(year, s1, year, money + b2); if (s1 == -1 && s2 == -1 && money + b1 < 0 && money + b2 < 0 && money + b1 + b2 >= 0) bruteforce(year, year, year, money + b1 + b2); } } void solve() { years = -1; sll money = (m - 12) * (a1 + a2); a1 *= 12; a2 *= 12; bruteforce(0, -1, -1, money); if (sell1 >= 0) sell1 = sell1 * 12 + m - 12; if (sell2 >= 0) sell2 = sell2 * 12 + m - 12; } int main() { std::ios::sync_with_stdio(false); int t; cin >> t; for (int i = 0; i < t; ++i) { input(); solve(); output(); } return 0; }