#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long int b, p, first, h, c;
    cin >> b >> p >> first >> h >> c;
    if (b >= 2 * (p + first)) {
      cout << p * h + first * c << '\n';
      continue;
    }
    if (h > c) {
      if (p * 2 <= b) {
        cout << h * p + c * ((b - (2 * p)) / 2) << '\n';
        continue;
      }
      cout << (b / 2) * h << '\n';
      continue;
    }
    if (first * 2 <= b) {
      cout << c * first + h * ((b - (2 * first)) / 2) << '\n';
      continue;
    }
    cout << (b / 2) * c << '\n';
  }
  return 0;
}
