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
88
89
#define START_MASK (1 << 30)
#include <string>
#include <cstdio>

using namespace std;
string leftSide;
string rightSide;
bool last2p1 = false;

int ones = 0;

void appendTwo()
{
	if (last2p1)
	{
		leftSide += "(";
		rightSide += ")*(1+1)";
	}
	else
	{
		rightSide += "*(1+1)";
	}
	last2p1 = false;
	ones += 2;
}

void appendTwoPlusOne()
{
	appendTwo();
	rightSide += "+1";
	last2p1 = true;
	ones++;
}

void Solve(int n)
{
	int mask = START_MASK;
	bool first = false;
	bool bit;
	while (mask > 0)
	{
		bit = n & mask;
		if (!first)
		{
			if (bit)
			{
				first = true;
				rightSide = "1";
			}
		}
		else
		{
			if (bit)
			{
				appendTwoPlusOne();
			}
			else
			{
				appendTwo();
			}
		}
		mask >>= 1;
	}
}

int main()
{
	int queries, n;
	scanf("%d", &queries);
	for (int q = 0; q < queries; q++)
	{
		scanf("%d", &n);
		Solve(n);
		if ((leftSide.length() == 0 && rightSide.length() == 0) || ones > 100)
		{
			printf("NIE\n");
		}
		else
		{
			printf("%s%s\n", leftSide.c_str(), rightSide.c_str());
		}
		leftSide = rightSide = "";
		last2p1 = false;
		ones = 0;
	}


	return 0;
}