#include <bits/stdc++.h>
using namespace std;
int main() {
  long long test;
  cin >> test;
  while (test--) {
    long long b, p, f, h, c;
    cin >> b >> p >> f >> h >> c;
    long long profit = 0;
    if (h > c) {
      if (b - 2 * p >= 0) {
        profit += p * h;
        b = b - 2 * p;
        if (b - 2 * f >= 0) {
          profit += f * c;
        } else {
          profit += c * (b / 2);
        }
      } else {
        profit += h * (b / 2);
      }
    } else {
      if (b - 2 * f >= 0) {
        profit += f * c;
        b = b - 2 * f;
        if (b - 2 * p >= 0) {
          profit += p * h;
        } else {
          profit += h * (b / 2);
        }
      } else {
        profit += c * (b / 2);
      }
    }
    cout << profit << "\n";
  }
}
