#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned int t;
  cin >> t;
  while (t-- > 0) {
    unsigned int b, p, f, h, c;
    cin >> b >> p >> f >> h >> c;
    b /= 2;
    if (h > c) {
      swap(p, f);
      swap(h, c);
    }
    if (b < p + f) {
      if (b > f) {
        p = b - f;
      } else {
        p = 0;
        f = b;
      }
    }
    cout << p * h + f * c << endl;
  }
  return 0;
}
