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
// Zadanie: Jedynki [B]
// Autor: Arkadiusz Roussau

#include <iostream>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

int t, val;

void solve(int v) {
    string res = "";
    vector<int> bits;
    
    while (v > 0) {
        int r = v % 2;
        bits.push_back(r);
        v -= r;
        v /= 2;
    }
    
    for (int i = bits.size() - 1; i >= 0; --i) {
        if (i == bits.size() - 1) {
            res += "1";
        }
        else if (bits[i] == 1) {
            res += "+1)";
        }
        
        if (i > 0) {
            res += "*(1+1))";
        }
    }
    
    int c1 = 0, c2 = 0;
    
    for (int i = 0; i < res.length(); ++i) {
        if (res[i] == ')') {
            c1++;
        }
        else if (res[i] == '(') {
            c2++;
        }
    }
    
    string aux = "";
    
    for (int i = c2; i < c1; i++) {
        aux += "(";
    }
    
    res = aux + res;
    
    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> t;
    
    for (int i = 0; i < t; ++i) {
        cin >> val;
        solve(val);
    }
    
    return 0;
}