#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int buns, buns2, beef, chicken, hamb, chickb;
    cin >> buns >> beef >> chicken >> hamb >> chickb;
    buns2 = buns;
    int res = 0;
    res += min(buns / 2, beef);
    buns -= res * 2;
    res *= hamb;
    res += min(max(buns, 0) / 2, chicken) * chickb;
    int res2 = 0;
    res2 += min(buns2 / 2, chicken);
    buns2 -= res2 * 2;
    res2 *= chickb;
    res2 += min(max(buns2, 0) / 2, beef) * hamb;
    cout << max(res, res2) << endl;
  }
}
