Under construction

Still being built. Things may change

Four Fours

Interview

Time limit2sMemory limit256 MB

Summary
Using exactly four 4s joined by three operators from *, +, -, /, print the lexicographically first expression equal to each query value or no solution.
Level

Easy3 of 10

Topics
Brute force, Implementation
Solved
No attempts yet

Problem

Given an integer nn, build one expression whose value is nn. The expression uses the digit 4 exactly four times, with exactly three binary operators chosen from *, +, -, / placed between them. The digit 4 is the only number you may use. Joining fours into a larger number such as 44 or 444 is not allowed.

Division is integer division that truncates toward zero, so 4 / 4 / 4 is 0 and not 0.25. Operators keep their usual precedence, so 4 + 4 * 4 is 20 and not 32.

Only 64 expressions fit these rules, so some values of nn cannot be reached by any of them. For example, no expression gives n=11n = 11.

Input

The first line contains the number of test cases mm. (1≤m≤10001 \le m \le 1000)

Each of the next mm lines contains one integer nn. (−1000000≤n≤1000000-1000000 \le n \le 1000000)

Output

Print one line for each test case.

If an expression whose value is nn exists, print it in the form 4 * 4 - 4 * 4 = 0, with a single space between every number, operator, and the equals sign. If no such expression exists, print no solution.

If several expressions have the value nn, print only the one whose printed string comes first in lexicographic order. The four fours are identical, so this is the same as comparing the three operators from left to right under the order *, +, -, /.

Hint

There are three operator slots and four candidates for each slot, so only 64 expressions exist. Evaluate all 64 once and store, for each value, the expression that comes first in lexicographic order. Every test case then costs one table lookup.

Examples2

  1. Example 1

    Input
    5
    9
    0
    7
    11
    24
    
    Expected output
    4 + 4 + 4 / 4 = 9
    4 * 4 - 4 * 4 = 0
    4 + 4 - 4 / 4 = 7
    no solution
    4 * 4 + 4 + 4 = 24
    
  2. Example 2

    Input
    3
    -1
    -60
    3
    
    Expected output
    4 - 4 - 4 / 4 = -1
    4 - 4 * 4 * 4 = -60
    no solution