#include<iostream>
using namespace std;
class Complex //复数类
{
public:
Complex(double real = 0, double imag = 0);
Complex operator+(Complex& com);
Complex operator-(Complex& com);
Complex operator*(Complex& com);
Complex operator/(Complex& com);
double& operator[](int i);
double operator[](int i) const;
friend ostream& operator<<(ostream& os, Complex& com);//友元函数重载提取运算符"<<"
friend istream& operator>>(istream& is, Complex& com);//友元函数重载插入运算符">>"
private:
double real;//实数
double imag;//虚数
};
Complex::Complex (double a, double b){
real = a;
imag = b;
}
Complex Complex::operator+(Complex& com){
Complex a;
a.real = real + com.real;
a.imag = imag + com.imag;
return a;
}
Complex Complex::operator-(Complex& com){
Complex a;
a.real = real -com.real;
a.imag = imag- com.imag;
return a;
}
Complex Complex::operator*(Complex& com){
Complex a;
a.real = real * com.real - imag * com.imag;
a.imag = imag * com.real + real * com.imag;
return a;
}
Complex Complex::operator/(Complex& com){
Complex a;
a.real = (real * com.real + imag * com.imag)/(com.real*com.real + com.imag*com.imag);
a.imag = (imag * com.real - real *com.imag)/(com.real*com.real + com.imag*com.imag);
return a;
}
double& Complex::operator[](int i){
if(i==0) return real;
else if(i==1) return imag;
}
double Complex::operator[](int i) const{
if(i==0) return real;
else if(i==1) return imag;
}
ostream& operator<<(ostream& os, Complex& com){
if(com.real !=0) cout<<com.real;
if(com.real!=0&&com.imag!=0){
if(com.imag==1) cout<<"+i";
else if(com.imag==-1) cout<<"-i";
else if(com.imag>0) cout<<"+"<<com.imag<<"i";
else cout<<com.imag<<"i";
}
if(com.real==0&&com.imag!=0){
if(com.imag==1) cout<<"i";
else if(com.imag==-1) cout<<"-i";
else if(com.imag>0) cout<<com.imag<<"i";
else cout<<com.imag<<"i";
}
if(com.imag==0&&com.real==0) cout<<0;
return os;
}
istream& operator>>(istream& is, Complex& com){
cin>>com.real>>com.imag;
return is;
}
int main()
{
int T;
cin >> T;
while (T--) {
Complex com1, com2;
cin >> com1;
cout << com1 << endl;
cout << com1[0] << " " << com1[1] << endl;
cin >> com2;
cout << com2 << endl;
cout << com2[0] << " " << com2[1] << endl;
Complex c1 = com1 + com2;
cout << "(" << com1 << ")+(" << com2 << ")=" << c1 << endl;
Complex c2 = com1 - com2;
cout << "(" << com1 << ")-(" << com2 << ")=" << c2 << endl;
Complex c3 = com1 * com2;
cout << "(" << com1 << ")*(" << com2 << ")=" << c3 << endl;
Complex c4 = com1 / com2;
cout << "(" << com1 << ")/(" << com2 << ")=" << c4 << endl;
}
return 0;
}