#include #include #ifdef max #undef max #endif using namespace std; int main() { int case_number; cin >> case_number; for (int case_count = 0; case_count != case_number; ++case_count){ int start, year, kind; long long temp_max = -1; cin >> start >> year >> kind; for (int i = 0; i < kind; ++i){ int type, h; long double r; cin >> type >> r >> h; long long money = start; if (type == 1){ for (int j = 0; j < year; ++j){ money = money + (long long)((long double)money * r) - h; } } else { long long t = 0; for (int j = 0; j < year; ++j){ t += (long long)((long double)money * r); money -= h; } money += t; } //cout << money << " " << type << endl; temp_max = max(temp_max, money); } cout << temp_max << endl; //cout << endl; } return 0; }