#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, b, p, f, h, c;
  cin >> t;
  for (int k = 0; k < t; k++) {
    cin >> b >> p >> f >> h >> c;
    if (2 * p + 2 * f <= b)
      cout << p * h + f * c << endl;
    else {
      if (b == 1)
        cout << 0 << endl;
      else {
        if (c > h) {
          if (2 * f >= b)
            cout << b / 2 * c << endl;
          else
            cout << f * c + (b - 2 * f) / 2 * h << endl;
        } else {
          if (2 * p >= b)
            cout << b / 2 * h << endl;
          else
            cout << p * h + (b - 2 * p) / 2 * c << endl;
        }
      }
    }
  }
  return 0;
}
