#include <iostream>
using namespace std;
struct SoPhuc {
double thuc, ao;
};
SoPhuc Cong(SoPhuc a, SoPhuc b) {
return {a.thuc + b.thuc, a.ao + b.ao};
}
SoPhuc Tru(SoPhuc a, SoPhuc b) {
return {a.thuc - b.thuc, a.ao - b.ao};
}
SoPhuc Nhan(SoPhuc a, SoPhuc b) {
return {(a.thuc * b.thuc) - (a.ao * b.ao), (a.thuc * b.ao) + (b.thuc * a.ao)};
}
void HienThi(SoPhuc a) {
if (a.thuc != 0) cout << a.thuc;
if (a.ao != 0) {
if (a.ao == -1) {
cout << (a.thuc != 0 ? " - i" : "-i");
} else if (a.ao == 1) {
cout << (a.thuc != 0 ? " + i" : "i");
} else {
if (a.thuc != 0) {
cout << (a.ao > 0 ? " + " : " - ") << abs(a.ao) << "i";
} else {
cout << a.ao << "i";
}
}
} else if (a.thuc == 0) {
cout << "0";
}
cout << '\n';
}
void Input(SoPhuc &a) {
cin >> a.thuc >> a.ao;
}
int main() {
int n;
cin >> n;
while (n--) {
SoPhuc a, b;
Input(a);
Input(b);
HienThi(Cong(a, b));
HienThi(Tru(a, b));
HienThi(Nhan(a, b));
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IFNvUGh1YyB7CiAgICBkb3VibGUgdGh1YywgYW87Cn07CgpTb1BodWMgQ29uZyhTb1BodWMgYSwgU29QaHVjIGIpIHsKICAgIHJldHVybiB7YS50aHVjICsgYi50aHVjLCBhLmFvICsgYi5hb307Cn0KClNvUGh1YyBUcnUoU29QaHVjIGEsIFNvUGh1YyBiKSB7CiAgICByZXR1cm4ge2EudGh1YyAtIGIudGh1YywgYS5hbyAtIGIuYW99Owp9CgpTb1BodWMgTmhhbihTb1BodWMgYSwgU29QaHVjIGIpIHsKICAgIHJldHVybiB7KGEudGh1YyAqIGIudGh1YykgLSAoYS5hbyAqIGIuYW8pLCAoYS50aHVjICogYi5hbykgKyAoYi50aHVjICogYS5hbyl9Owp9Cgp2b2lkIEhpZW5UaGkoU29QaHVjIGEpIHsKICAgIGlmIChhLnRodWMgIT0gMCkgY291dCA8PCBhLnRodWM7CiAgICBpZiAoYS5hbyAhPSAwKSB7CiAgICAgICAgaWYgKGEuYW8gPT0gLTEpIHsKICAgICAgICAgICAgY291dCA8PCAoYS50aHVjICE9IDAgPyAiIC0gaSIgOiAiLWkiKTsKICAgICAgICB9IGVsc2UgaWYgKGEuYW8gPT0gMSkgewogICAgICAgICAgICBjb3V0IDw8IChhLnRodWMgIT0gMCA/ICIgKyBpIiA6ICJpIik7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaWYgKGEudGh1YyAhPSAwKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IChhLmFvID4gMCA/ICIgKyAiIDogIiAtICIpIDw8IGFicyhhLmFvKSA8PCAiaSI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IGEuYW8gPDwgImkiOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfSBlbHNlIGlmIChhLnRodWMgPT0gMCkgewogICAgICAgIGNvdXQgPDwgIjAiOwogICAgfQogICAgY291dCA8PCAnXG4nOwp9Cgp2b2lkIElucHV0KFNvUGh1YyAmYSkgewogICAgY2luID4+IGEudGh1YyA+PiBhLmFvOwp9CmludCBtYWluKCkgewogICAgaW50IG47CiAgICBjaW4gPj4gbjsKICAgIHdoaWxlIChuLS0pIHsKICAgICAgICBTb1BodWMgYSwgYjsKICAgICAgICBJbnB1dChhKTsKICAgICAgICBJbnB1dChiKTsKCiAgICAgICAgSGllblRoaShDb25nKGEsIGIpKTsKICAgICAgICBIaWVuVGhpKFRydShhLCBiKSk7CiAgICAgICAgSGllblRoaShOaGFuKGEsIGIpKTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==