#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <queue>
using namespace std;
#define LL long long
template<class T>
T C(T a, char op, T b) {
if (op=='+') return a + b;
if (op=='-') return a - b;
if (op=='*') return a * b;
throw 0;
}
template<class T, class P>
string V(T a, char op, P b) {
stringstream ss;
ss << '(' << a << op << b << ')';
return string(ss.str());
}
vector<int> ke[2000];
int trace[2000];
int match(int n, int m) {
vector<int> visited(n, -1);
vector<int> ref(n);
vector<int> mx(n, -1);
vector<int> my(m, -1);
int cnt = 0;
for (int i=0; i<n; i++) if (mx[i] < 0) {
struct { int u, v; } res = {-1, -1};
queue<int> q;
q.push(i);
visited[i] = i;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v: ke[u]) {
if (my[v] >= 0 && visited[my[v]] != i) {
q.push(my[v]);
ref[my[v]] = u;
visited[my[v]] = i;
} else if (my[v] < 0) {
res = {u, v};
break;
}
}
if (res.u >= 0) break;
}
if (res.u >= 0) {
cnt++;
while (true) {
int vv = mx[res.u];
mx[res.u] = res.v;
my[res.v] = res.u;
if (res.u == i) break;
res = {ref[res.u], vv};
};
}
}
if (cnt < n) return cnt;
for (int i=0; i<n; i++) if (mx[i] >= 0) {
for (int j=0; j<(int)ke[i].size(); j++) {
if (ke[i][j] == mx[i]) {
trace[i] = j;
break;
}
}
} else trace[i] = -1;
return cnt;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int n; cin >> n; cin.ignore();
vector<vector<string>> view(n);
vector<vector<LL>> val(n);
for (int i=0; i<n; i++) {
string s;
getline(cin, s);
int cnt_op = 0;
LL num[4] = {0,0,0,0};
char op[4];
for (char c: s) {
if ('0' <= c && c <= '9') {
num[cnt_op] *= 10;
num[cnt_op] += c - '0';
} else {
op[cnt_op] = c;
cnt_op++;
}
}
if (cnt_op == 1) {
val[i].push_back(C(num[0], op[0], num[1]));
view[i].push_back(s);
}
if (cnt_op == 2) {
val[i].push_back(C(C(num[0],op[0],num[1]),op[1],num[2]));
val[i].push_back(C(num[0],op[0],C(num[1],op[1],num[2])));
view[i].push_back(V(V(num[0],op[0],num[1]),op[1],num[2]));
view[i].push_back(V(num[0],op[0],V(num[1],op[1],num[2])));
}
if (cnt_op == 3) {
val[i].push_back(C(C(C(num[0],op[0],num[1]),op[1],num[2]),op[2],num[3])); // 0 1 2
val[i].push_back(C(C(num[0],op[0],num[1]),op[1],C(num[2],op[2],num[3]))); // 0 2 1
val[i].push_back(C(C(num[0],op[0],C(num[1],op[1],num[2])),op[2],num[3])); // 1 0 2
val[i].push_back(C(num[0],op[0],C(C(num[1],op[1],num[2]),op[2],num[3]))); // 1 2 0
val[i].push_back(C(num[0],op[0],C(num[1],op[1],C(num[2],op[2],num[3])))); // 2 1 0
view[i].push_back(V(V(V(num[0],op[0],num[1]),op[1],num[2]),op[2],num[3])); // 0 1 2
view[i].push_back(V(V(num[0],op[0],num[1]),op[1],V(num[2],op[2],num[3]))); // 0 2 1
view[i].push_back(V(V(num[0],op[0],V(num[1],op[1],num[2])),op[2],num[3])); // 1 0 2
view[i].push_back(V(num[0],op[0],V(V(num[1],op[1],num[2]),op[2],num[3]))); // 1 2 0
view[i].push_back(V(num[0],op[0],V(num[1],op[1],V(num[2],op[2],num[3])))); // 2 1 0
}
/*
cout << s << endl;
for (int j=0; j<(int)ke[i].size(); j++) {
cout << "\t" << view[i][j] << '=' << ke[i][j] << endl;
}
*/
}
map<LL, int> map;
for (int i=0; i<n; i++) {
for (LL v: val[i]) {
if (!map.count(v)) map.insert({v, (int)map.size()});
ke[i].push_back(map[v]);
}
}
if ((int)map.size() < n) { cout << "NO SOLUTION"; return 0; }
int cnt = match(n, map.size());
if (cnt < n) { cout << "NO SOLUTION"; return 0; }
for (int i=0; i<n; i++) cout << view[i][trace[i]] << '\n';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPG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ICAgICAgICAgICBpZiAobXlbdl0gPj0gMCAmJiB2aXNpdGVkW215W3ZdXSAhPSBpKSB7CiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKG15W3ZdKTsKICAgICAgICAgICAgICAgICAgICByZWZbbXlbdl1dID0gdTsKICAgICAgICAgICAgICAgICAgICB2aXNpdGVkW215W3ZdXSA9IGk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG15W3ZdIDwgMCkgewogICAgICAgICAgICAgICAgICAgIHJlcyA9IHt1LCB2fTsgCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJlcy51ID49IDApIGJyZWFrOwogICAgICAgIH0KCiAgICAgICAgaWYgKHJlcy51ID49IDApIHsKICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICAgICAgICBpbnQgdnYgPSBteFtyZXMudV07CiAgICAgICAgICAgICAgICBteFtyZXMudV0gPSByZXMudjsKICAgICAgICAgICAgICAgIG15W3Jlcy52XSA9IHJlcy51OwogICAgICAgICAgICAgICAgaWYgKHJlcy51ID09IGkpIGJyZWFrOwogICAgICAgICAgICAgICAgcmVzID0ge3JlZltyZXMudV0sIHZ2fTsKICAgICAgICAgICAgfTsKICAgICAgICB9CiAgICB9CgogICAgaWYgKGNudCA8IG4pIHJldHVybiBjbnQ7CgogICAgZm9yIChpbnQgaT0wOyBpPG47IGkrKykgaWYgKG14W2ldID49IDApIHsKICAgICAgICBmb3IgKGludCBqPTA7IGo8KGludClrZVtpXS5zaXplKCk7IGorKykgewogICAgICAgICAgICBpZiAoa2VbaV1bal0gPT0gbXhbaV0pIHsKICAgICAgICAgICAgICAgIHRyYWNlW2ldID0gajsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfSBlbHNlIHRyYWNlW2ldID0gLTE7CgogICAgcmV0dXJuIGNudDsKfQoKaW50IG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoMCk7CiAgICBpbnQgbjsgY2luID4+IG47IGNpbi5pZ25vcmUoKTsKICAgIHZlY3Rvcjx2ZWN0b3I8c3RyaW5nPj4gdmlldyhuKTsKICAgIHZlY3Rvcjx2ZWN0b3I8TEw+PiB2YWwobik7CiAgICBmb3IgKGludCBpPTA7IGk8bjsgaSsrKSB7CiAgICAgICAgc3RyaW5nIHM7CiAgICAgICAgZ2V0bGluZShjaW4sIHMpOwoKICAgICAgICBpbnQgY250X29wID0gMDsKICAgICAgICBMTCBudW1bNF0gPSB7MCwwLDAsMH07CiAgICAgICAgY2hhciBvcFs0XTsKICAgICAgICBmb3IgKGNoYXIgYzogcykgewogICAgICAgICAgICBpZiAoJzAnIDw9IGMgJiYgYyA8PSAnOScpIHsKICAgICAgICAgICAgICAgIG51bVtjbnRfb3BdICo9IDEwOwogICAgICAgICAgICAgICAgbnVtW2NudF9vcF0gKz0gYyAtICcwJzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIG9wW2NudF9vcF0gPSBjOwogICAgICAgICAgICAgICAgY250X29wKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGlmIChjbnRfb3AgPT0gMSkgewogICAgICAgICAgICB2YWxbaV0ucHVzaF9iYWNrKEMobnVtWzBdLCBvcFswXSwgbnVtWzFdKSk7CiAgICAgICAgICAgIHZpZXdbaV0ucHVzaF9iYWNrKHMpOwogICAgICAgIH0KICAgICAgICBpZiAoY250X29wID09IDIpIHsKICAgICAgICAgICAgdmFsW2ldLnB1c2hfYmFjayhDKEMobnVtWzBdLG9wWzBdLG51bVsxXSksb3BbMV0sbnVtWzJdKSk7CiAgICAgICAgICAgIHZhbFtpXS5wdXNoX2JhY2soQyhudW1bMF0sb3BbMF0sQyhudW1bMV0sb3BbMV0sbnVtWzJdKSkpOwogICAg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LyAwIDIgMQogICAgICAgICAgICB2aWV3W2ldLnB1c2hfYmFjayhWKFYobnVtWzBdLG9wWzBdLFYobnVtWzFdLG9wWzFdLG51bVsyXSkpLG9wWzJdLG51bVszXSkpOyAvLyAxIDAgMgogICAgICAgICAgICB2aWV3W2ldLnB1c2hfYmFjayhWKG51bVswXSxvcFswXSxWKFYobnVtWzFdLG9wWzFdLG51bVsyXSksb3BbMl0sbnVtWzNdKSkpOyAvLyAxIDIgMAogICAgICAgICAgICB2aWV3W2ldLnB1c2hfYmFjayhWKG51bVswXSxvcFswXSxWKG51bVsxXSxvcFsxXSxWKG51bVsyXSxvcFsyXSxudW1bM10pKSkpOyAvLyAyIDEgMAogICAgICAgIH0KCiAgICAgICAgLyoKICAgICAgICBjb3V0IDw8IHMgPDwgZW5kbDsKICAgICAgICBmb3IgKGludCBqPTA7IGo8KGludClrZVtpXS5zaXplKCk7IGorKykgewogICAgICAgICAgICBjb3V0IDw8ICJcdCIgPDwgdmlld1tpXVtqXSA8PCAnPScgPDwga2VbaV1bal0gPDwgZW5kbDsKICAgICAgICB9CiAgICAgICAgKi8KICAgIH0KICAgIG1hcDxMTCwgaW50PiBtYXA7CiAgICBmb3IgKGludCBpPTA7IGk8bjsgaSsrKSB7CiAgICAgICAgZm9yIChMTCB2OiB2YWxbaV0pIHsKICAgICAgICAgICAgaWYgKCFtYXAuY291bnQodikpIG1hcC5pbnNlcnQoe3YsIChpbnQpbWFwLnNpemUoKX0pOwogICAgICAgICAgICBrZVtpXS5wdXNoX2JhY2sobWFwW3ZdKTsKICAgICAgICB9CiAgICB9CgogICAgaWYgKChpbnQpbWFwLnNpemUoKSA8IG4pIHsgY291dCA8PCAiTk8gU09MVVRJT04iOyByZXR1cm4gMDsgfQogICAgaW50IGNudCA9IG1hdGNoKG4sIG1hcC5zaXplKCkpOwogICAgaWYgKGNudCA8IG4pIHsgY291dCA8PCAiTk8gU09MVVRJT04iOyByZXR1cm4gMDsgfQogICAgZm9yIChpbnQgaT0wOyBpPG47IGkrKykgY291dCA8PCB2aWV3W2ldW3RyYWNlW2ldXSA8PCAnXG4nOwogICAgcmV0dXJuIDA7Cn0K