#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
while (true) {
int K;
cin >> K;
if (!cin || K == 0) break;
double a,b,c,d;
cin >> a >> b;
cin >> c >> d;
complex<double> z1(a, b);
complex<double> z2(c, d);
complex<double> result;
if (K == 1) {
// 複數指數運算 z1^z2
result = pow(z1, z2);
} else if (K == 2) {
// 複數對數底 z1,真數 z2
// log_base(z2) = log(z2) / log(z1)
result = log(z2) / log(z1);
}
double p = result.real();
double q = result.imag();
auto rnd6 = [](double x) {
return round(x * 1000000.0) / 1000000.0;
};
p = rnd6(p);
q = rnd6(q);
// 消除 -0.000000
if (fabs(p) < 0.0000005) p = 0.0;
if (fabs(q) < 0.0000005) q = 0.0;
cout << fixed << setprecision(6);
if (q >= 0) {
cout << p << " + " << q << "i\n";
} else {
cout << p << " - " << fabs(q) << "i\n";
}
}
return 0;
}