#include <iostream>
#include <vector>
using namespace std;
int card[12];
int input[11];
int max_num = -100000000;
int min_num = 100000000;
int N;
void solution(int size, int add, int sub, int mul, int div) {
if (size == N-1) {
int sum = 0;
sum = card[0];
for (int n = 0; n < N-1; n++) {
if (input[n] == 1)
sum = sum + card[n + 1];
else if (input[n] == 2)
sum = sum - card[n + 1];
else if (input[n] == 3)
sum = sum * card[n + 1];
else if (input[n] == 4)
sum = sum / card[n + 1];
}
if (sum > max_num)
max_num = sum;
if (sum < min_num)
min_num = sum;
return;
}
if (add != 0) {
input[size] = 1;
solution(size + 1, add - 1, sub, mul, div);
}
if (sub != 0) {
input[size] = 2;
solution(size + 1, add, sub - 1, mul, div);
}
if (mul != 0) {
input[size] = 3;
solution(size + 1, add, sub, mul - 1, div);
}
if (div != 0) {
input[size] = 4;
solution(size + 1, add, sub, mul, div - 1);
}
}
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
max_num = -100000000;
min_num = 100000000;
int cal[4];
int add, sub, mul, div;
cin >> N;
cin >> add >> sub >> mul >> div;
for (int n = 0; n < N; n++) {
cin >> card[n];
}
solution(0, add, sub, mul, div);
int answer = 0;
answer = max_num - min_num;
cout << "#" << t << " " << answer << endl;
}
return 0;
}