#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long b, p, f, h, c, pr = 0;
    cin >> b >> p >> f >> h >> c;
    if (b % 2 == 1) b--;
    if (h > c) {
      if (2 * p <= b) {
        pr += h * (p);
        b -= 2 * p;
        if (2 * f <= b)
          pr += c * (f);
        else
          pr += c * (b / 2);
      } else
        pr += h * (b / 2);
    } else {
      if (2 * f <= b) {
        pr += c * (f);
        b -= 2 * f;
        if (2 * p <= b)
          pr += h * (p);
        else
          pr += h * (b / 2);
      } else
        pr += c * (b / 2);
    }
    cout << pr << '\n';
  }
  return 0;
}
