#include <bits/stdc++.h>
using namespace std;
int main() {
  long long test;
  cin >> test;
  while (test--) {
    long long b, bp, cc;
    cin >> b >> bp >> cc;
    long long ham, cb;
    cin >> ham >> cb;
    long long profit1, profit2;
    profit1 = ham * min(bp, b / 2);
    long long rem = b - 2 * min(bp, b / 2);
    profit2 = cb * min(cc, rem / 2);
    long long totalProfit1 = (profit1 + profit2);
    profit1 = cb * min(cc, b / 2);
    rem = b - 2 * min(cc, b / 2);
    profit2 = ham * min(bp, rem / 2);
    long long totalProfit2 = (profit1 + profit2);
    cout << max(totalProfit1, totalProfit2) << endl;
  }
}
