#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int b, p, f, c_h, c_c;
    cin >> b >> p >> f >> c_h >> c_c;
    int res = 0;
    if (c_h > c_c) {
      while (p > 0 && b / p < 2) {
        p--;
      }
      b -= (2 * p);
      res += (c_h * p);
      while (f > 0 && b / f < 2) {
        f--;
      }
      b -= (2 * f);
      res += (c_c * f);
    } else {
      while (f > 0 && b / f < 2) {
        f--;
      }
      b -= (2 * f);
      res += (c_c * f);
      while (p > 0 && b / p < 2) {
        p--;
      }
      b -= (2 * p);
      res += (c_h * p);
    }
    cout << res << endl;
  }
}
