#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long b, p, f, h, c;
    cin >> b >> p >> f;
    cin >> h >> c;
    long long total = min(b / 2, p + f);
    long long maxi = 0;
    for (long long i = 0; i <= p; i++) {
      long long left = total - i;
      if (left <= f) {
        if (left < 0) {
          break;
        }
        maxi = max(maxi, i * h + left * c);
      }
    }
    cout << maxi << endl;
  }
}
