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
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;

public class jed {

    static String readInput() throws IOException {
        BufferedInputStream bis = new BufferedInputStream(System.in);
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        int result = bis.read();
        while (result != -1) {
            buf.write((byte) result);
            result = bis.read();
        }
        return buf.toString();
    }

    static String ones(int k, String partial, int ones) {
        if (ones > 99) return "NIE";
        if (k == 5 && ones <= 95) {
            return String.format(partial, "1+1+1+1+1");
        }
        if (k == 3 && ones <= 97) {
            return String.format(partial, "1+1+1");
        }
        if (k == 2 && ones <= 98) {
            return String.format(partial, "1+1");
        }
        if (k == 1) return String.format(partial, "1");
        if (k % 5 == 0) {
            return ones(k / 5, String.format(partial, "(1+1+1+1+1)*(%s)"), ones + 5);
        } else if (k % 3 == 0) {
            return ones(k / 3, String.format(partial, "(1+1+1)*(%s)"), ones + 3);
        } else if (k % 2 == 0) {
            return ones(k / 2, String.format(partial, "(1+1)*(%s)"), ones + 2);
        } else {
            return ones(k-1, String.format(partial, "1+(%s)"), ones + 1);
        }
    }

    public static void main(String[] args) throws IOException {
        String[] tokenizedInput = readInput().split("\\s");
        int[] ns = Arrays.stream(tokenizedInput).mapToInt(Integer::parseInt).toArray();
        int t = ns[0];
        for (int i = 0; i < t; i++) {
            int k = ns[i+1];
            System.out.println(ones(k, "%s", 0));
        }
    }

}