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