=================================================
import java.util.Scanner;
class Ex00005
{
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
int i,j,nt,n[][];
String inp,t[];
do
{
nt=scn.nextInt();
if ((nt==0)||(!scn.hasNext()))
break;
n=new int [nt][5];
for (i=0;i<nt;i++)
{
scn=new Scanner(System.in);
inp=scn.nextLine();
t=inp.split(" ");
for (j=0;j<4;j++)
n[i][j]=Integer.valueOf(t[j]);
}
for (i=0;i<nt;i++)
{
n[i][4]=n[i][3]*n[i][3]/n[i][2];
if (2*n[i][2]==n[i][1]+n[i][3])
n[i][4]=2*n[i][3]-n[i][2];
System.out.println(n[i][4]);
}
}
while (scn.hasNext());
}
}