#3334: 還是過不了!


jeff90113 (jeff)


#include<iostream>
using namespace std;
int main(){
 int n, a, b, c, d;
 cin >> n;
 while ( n -- ) {
  a = 0;
  b = 0;
  c = 0;
  d = 0;
  cin >> a >> b >> c >> d;
  if(( b - a ) == ( c - b ))
   cout << d + b - a;
  if(( b / a ) == ( c / b ))
   cout << d * ( b / a );
  cout << "\n" ;
 }  
}