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
#include <iostream>
using namespace std;

class Unarizer
{
	public:
	string unarize(int n, int base)
	{
		_n = n;
		_base = base;
		_len = 0;
		_unarize();
		if(_len > 100)
			return "NIE";
		return _exp;
	}
	int length(){return _len;}
	
	private:
	string _exp;
	int _len;
	int _base;
	int _n;
	void _unarize()
	{
		int dig = _n % _base;
		_n /= _base;
		if(dig > 0 && _n > 0)
			_exp += '(';
		_digit(dig);
		if(_n == 0)
			return;
		if(dig > 0)
			_exp += '+';
		_exp += '(';
		_digit(_base);
		_exp += ')';
		_exp += '*';
		_unarize();
		if(dig > 0)
		_exp += ')';
		
	}
	
	//dopisuje do wyrazenia liczbe n w postaci sumy jedynek
	void _digit(int n)
	{
		if(n > 0)
		{
			_len += n--;
			_exp += '1';
			while(n-- > 0)
			_exp += "+1";
		}
	}
};


int main()
{
ios_base::sync_with_stdio(0);	
int t,n;
	cin>>t;
	while(t--)
	{
		cin>>n;
		Unarizer u;
		string ans;
		int b = 2;
		do{
			ans = u.unarize(n, b);
			b++;
		}while(ans == "NIE" && b <= 8);
		cout<<ans<<'\n';
	}
	return 0;
}