#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int b, p, f, h, c;
    cin >> b >> p >> f >> h >> c;
    int ans = 0;
    for (int i = 0; i <= p; ++i) {
      int num1 = min(i, b / 2);
      int num2 = min(f, (b - num1 * 2) / 2);
      ans = max(ans, num1 * h + num2 * c);
    }
    cout << ans << endl;
  }
  return 0;
}
