#include <iostream>
using namespace std;
int main() {
int t, seq[3];
cin >> t;
for (int j = 1; j <= t; j++){
for(int i = 0; i<= 3; i++){
cin >> seq[i];
}
if(seq[0] + seq[3] == seq[1] + seq[2]){
cout << seq[0] << seq[1] << seq[2] << seq[3] << seq[3] + seq[1] - seq[0] << endl;
}
else{
cout << seq[0] << seq[1] << seq[2] << seq[3] << seq[3] * seq[1] / seq[0] << endl;
}
}
return 0;
}