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
#include <cstdio>
#define MAX 100

int t,k;
int counter;
int brackets;

void roz(int k2) {
    if(k2 == 1) {
        if(counter <= MAX) {
            for(int a = 0;a < brackets;a++)
                printf("(");
        }
        return ;
    }
    if(k2 % 5 == 0) {
        counter += 5;
        roz(k2/5);
        if(counter <= MAX) {
            if(k2/5 == 1) printf("(1+1+1+1+1)");
            else printf("*(1+1+1+1+1)");
        }
    } else if(k2 % 3 == 0) {
        counter += 3;
        roz(k2/3);
        if(counter <= MAX) {
            if(k2/3 == 1) printf("(1+1+1)");
            else printf("*(1+1+1)");
        }
    }
    else if(k2 % 2 == 0) {
        counter += 2;
        roz(k2/2);
        if(counter <= MAX) {
            if(k2/2 == 1) printf("(1+1)");
            else printf("*(1+1)");
        }
    } else {
        counter += 1;
        if(k != k2) brackets++;
        roz(k2-1);
        if(counter <= MAX) {
            if(k == k2) printf("+1");
            else printf("+1)");
        }
    }
}

int main() {
    scanf("%d",&t);
    while(t--) {
        scanf("%d",&k);
        if(k == 1) printf("1\n");
        else {
            counter = 0;
            brackets = 0;
            roz(k);
            if(counter <= MAX) printf("\n");
            else printf("NIE\n");
        }
    }
}