#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << '\n';
}
const long long N = 3e5 + 50, oo = 1e18 + 100, mod = 1e9 + 7;
const long double eps = 1e-9, PI = 2 * acos(0.0);
vector<long long> g[N];
vector<long long> visit(N, 0);
long long n, m, k;
long long cnt = 0;
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long b, p, f, h, c;
    cin >> b >> p >> f >> h >> c;
    cnt = 0;
    b /= 2;
    if (h > c) {
      long long x = min(b, p);
      b -= x;
      cnt += x * h;
      x = min(b, f);
      cnt += x * c;
    } else {
      long long x = min(b, f);
      b -= x;
      cnt += x * c;
      x = min(b, p);
      cnt += x * h;
    }
    cout << cnt << '\n';
  }
}
