#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    int p1, p2;
    cin >> p1;
    cin >> p2;
    int min_no = min(b, c);
    if (a <= 1) {
      cout << 0 << "\n";
      continue;
    }
    if (b * 2 + c * 2 > a) {
      int p = 0;
      if (p2 >= p1) {
        if (c * 2 > a) {
          cout << (a / 2) * p2 << "\n";
          continue;
        } else {
          p += c * p2;
          if ((a - c * 2) <= 1) {
            cout << p << "\n";
            continue;
          }
          p += ((a - c * 2) / 2) * p1;
          cout << p << "\n";
          continue;
        }
      } else if (p1 > p2) {
        if (b * 2 > a) {
          cout << (a / 2) * p1 << "\n";
          continue;
        } else {
          p += b * p1;
          if ((a - b * 2) <= 1) {
            cout << p << "\n";
            continue;
          }
          p += ((a - b * 2) / 2) * p2;
          cout << p << "\n";
          continue;
        }
      }
    } else {
      int p = 0;
      p += (p2 * c) + (p1 * b);
      cout << p << "\n";
      continue;
    }
  }
  return 0;
}
