import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int T = kb.nextInt();
for(int i=0; i<T; i++) {
int P = kb.nextInt();
int Q = kb.nextInt();
int R = kb.nextInt();
int S = kb.nextInt();
int W = kb.nextInt();
int ACharge = W*P;
int BCharge = 0;
if(W>R) {
BCharge = Q+ S*(W-R);
}else {
BCharge = Q;
}
sb.append("#").append(i+1).append(" ");
if(ACharge>BCharge) {
sb.append(BCharge);
}else {
sb.append(ACharge);
}
sb.append('\n');
}
System.out.print(sb.toString());
}
}