#include<stdio.h>
int main () {
int n;
scanf("%d",&n);
int s[n][5];
for(int i = 0; i < n; i++) {
for(int j = 0; j < 4; j++) {
scanf("%d",&s[i][j]);
}
}
for(int i = 0; i < n; i++) {
if(s[i][3] - s[i][2] == s[i][2] - s[i][1] && s[i][2] - s[i][1] == s[i][1] - s[i][0] ) {
s[i][4] = s[i][3] + s[i][2] - s[i][1];
} else {
s[i][4] = s[i][3] * s[i][2] / s[i][1];
}