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