public class Main1{
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++) {
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d=sc.nextInt();
int e=sc.nextInt();
int time = 0;
int count;
if(a==d) {
time=e-b;
count=(int) (c*Math.pow(2, time));
System.out.println(count);
}
else {
for(int j=a;j<d;j++) {
if(j==2) {
time+=28;
}
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12) {
time+=31;
}if(j==4||j==6||j==9||j==11) {
time+=30;
}
}
time=time+e-b;
count=(int) (c*Math.pow(2, time));
System.out.println(count);
}
}
}
}