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
 96
 97
 98
 99
100
101
102
103
104
105
106
#include <iostream>
#include <vector>
using namespace std;

bool tab[1001];
vector<int> primes;


void sito()
{
    for(int i = 4; i<=1000; i+=2)
        tab[i] = true;
    for(int i = 3; i<=1000; i++)
        if(tab[i] == false)
            for(int j = 3*i; j<=1000; j+=(2*i))
                tab[j] = true;
    for(int i = 2; i<=1000; i++)
        if(tab[i] == false)
            primes.push_back(i);
    return;
}

void printNum(int n)
{
    cout << '1';
    for(int j = 1; j<n; j++)
        cout << "+1";
    cout << endl;
    return;
}

void printNum(vector<int> numbs)
{
    cout << "(1";
    for(int j = 1; j < numbs[0]; j++)
        cout << "+1";
    cout << ')';
    for(uint32_t i = 1; i<numbs.size(); i++)
    {
        cout << "*(1";
        for(int j = 1; j < numbs[i]; j++)
            cout << "+1";
        cout << ')';
    }
    cout << endl;
    return;
}

void solve(const int k)
{
    if(k<=1000)
        if(tab[k] == false){
            if(k>100)
            {
                cout << "NIE" << endl;
                return;
            }else{
                printNum(k);
                return;
            }
        }
    vector<int> rozk;
    int counter = 0;
    int n = k;
    for(int i = 0; n>1&&k >= primes[i]*primes[i];i++)
        while(n%primes[i] == 0)
        {
            rozk.push_back(primes[i]);
            counter+=primes[i];
            n/=primes[i];
            if(counter>100)
            {
                cout << "NIE" << endl;
                return;
            }
        }
    if(n>1)
    {
        rozk.push_back(n);
        counter+=n;
        if(counter>100)
        {
            cout << "NIE" << endl;
            return;
        }
    }
    printNum(rozk);
    return;
}



int main()
{
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    sito();
    int k;
    while(t--)
    {
        cin >> k;
        solve(k);
    }
    return 0;
}