#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 10;
int main() {
  int T = read();
  while (T--) {
    int b = read(), p = read(), f = read();
    int h = read(), c = read(), ans = 0;
    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 100; j++) {
        int num1 = (i + j) * 2, num2 = i, num3 = j;
        if (num1 > b || num2 > p || num3 > f)
          continue;
        else
          ans = max(ans, i * h + j * c);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
