#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    int buns, beef, chicken, hamP, burgerP;
    int total = 0;
    cin >> buns >> beef >> chicken;
    cin >> hamP >> burgerP;
    if (hamP > burgerP) {
      if (buns >= 2 * beef) {
        total = hamP * beef;
        buns = buns - (2 * beef);
        total = total + min(buns / 2, chicken) * burgerP;
      } else {
        total = (buns / 2) * hamP;
      }
    } else if (burgerP > hamP) {
      if (buns >= 2 * chicken) {
        total = burgerP * chicken;
        buns = buns - (2 * chicken);
        total = total + min(buns / 2, beef) * hamP;
      } else {
        total = (buns / 2) * burgerP;
      }
    } else {
      total = min(buns / 2, beef + chicken) * burgerP;
    }
    cout << total << endl;
    t--;
  }
}
