#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int N = 2e5 + 123;
int func(int b, int p, int f, int h, int c) {
  int cnt1 = min(b / 2, p);
  b -= cnt1 * 2;
  int cnt2 = min(b / 2, f);
  return cnt1 * h + cnt2 * c;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int b, p, f;
    cin >> b >> p >> f;
    int x, y;
    cin >> x >> y;
    cout << max(func(b, p, f, x, y), func(b, f, p, y, x)) << "\n";
  }
}
