#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, b, p, f, h, c, ans = 0;
  cin >> t;
  while (t--) {
    scanf("%d %d %d", &b, &p, &f);
    scanf("%d %d", &h, &c);
    ans = 0;
    if (b < 2) {
      printf("0\n");
    } else {
      if (h >= c) {
        if (2 * p <= b) {
          ans += p * h;
          b -= 2 * p;
          if (2 * f <= b)
            ans += f * c;
          else {
            ans += b / 2 * c;
            b = 0;
          }
        } else {
          ans += b / 2 * h;
          b = 0;
        }
      } else {
        if (2 * f <= b) {
          ans += c * f;
          b -= 2 * f;
          if (2 * p <= b)
            ans += p * h;
          else {
            ans += b / 2 * h;
            b = 0;
          }
        } else {
          ans += b / 2 * c;
          b = 0;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
