1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <string>

using namespace std;

int ones = 0;

inline string simple_number(int num) {
	if (num == 1)
		return "1";
	string sb = "";
	for (int i = 0; i < num; i++) {
		sb += "1+";
	}
	sb.pop_back();
	return sb;
}

inline string number(int num) {
	return "(" + simple_number(num) + ")";
}

inline string sum(string a, string b) {
	return "(" + a + "+" + b + ")";
}

inline string mult(string a, string b) {
	return "(" + a + "*" + b + ")";
}

string decompose(int k) {
	int minR = 5;
	int bestQ = 0;
	for (int j = 5; j > 1; j--) {
		int curR = k % j;
		if (curR < minR) {
			minR = curR;
			bestQ = j;
		}
		if (curR == 0) {
			break;
		}
	}
	ones += bestQ + minR;
	if (ones > 100) {
		return "";
	}

	k /= bestQ;

	if (k == 1) {
		if (minR > 0)
			return sum(number(bestQ), number(minR));
		return number(bestQ);
	}
	else {
		string d = decompose(k);
		if (ones > 100)
			return "";
		if (minR > 0) {
			return sum(mult(number(bestQ), d), number(minR));
		}
		return mult(number(bestQ), d);
	}
}

int main() {
	int t,k;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> k;
		
		if (k <= 100) {
			cout << simple_number(k) << endl;
			continue;
		}
		ones = 0;
		string dec = decompose(k);
		if (ones <= 100) {
			cout << dec << endl;
		}
		else {
			cout << "NIE" << endl;
		}
	}
	return 0;
}