#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long b, p, f, h, c, ans = 0;
    cin >> b >> p >> f >> h >> c;
    for (long long i = 0; i <= p; i++) {
      long long temp;
      temp = min(i, b / 2) * h;
      temp += min((b - 2 * temp / h) / 2, f) * c;
      ans = max(temp, ans);
    }
    cout << ans << endl;
  }
}
