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
90
91
92
93
94
95
#include"bits/stdc++.h"
using namespace std;
int n, t;
vector<int> V;
void rozklad(int x)
{
	if(x<=5)
	{
		V.push_back(0);
		V.push_back(x);
		V.push_back(-1);
		return;			
	}

	int i=2;
	int dynks=sqrt(x);
	int pocz=x;
	while(x>1 and i<=dynks)	
	{
		if(i>=dynks)
		{	
			V.push_back(0);
			rozklad(x-1);
			V.push_back(1);
			V.push_back(-1);
		
			break;
		}
		while(x%i==0)
		{
			V.push_back(0);
			if(i>5)
			{
				rozklad(i-1);
				V.push_back(1);
				V.push_back(-1);
			}
			else
			{
				V.push_back(i);
				V.push_back(-1);	
			}
			x=x/i;
		}
		i++;
	}

	return;
}


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin>>n;
	while(n--)
	{
		string x;
		cin>>t;
		if(t==1)
		{	
			cout<<"1";
			continue;
		}

		rozklad(t);
		int poprz=-2;
		int ile=0;
		for(int i=0; i<V.size(); i++)
		{
			if(V[i]==-1)x+=")";
			if(V[i]==0)
			{
				if(poprz==-1)
					x+="*";			
				x+="(";
			}
			if(V[i]==1){x+="+1";ile++;}
			poprz=V[i];
			if(V[i]>1)
			{
				x+="1";
				ile++;
				while(--V[i]){x+="+1";}
			}
		}
		if(ile<=100)cout<<x<<"\n";
		else cout<<"NIE\n";
		V.clear();
		x.clear();
	}
	return 0;
}