Under construction

Still being built. Things may change

A DP Problem

Time limit1sMemory limit128 MB

Summary
Parse each linear equation without parentheses, solve for x, and report the floored solution or whether it is impossible or an identity.
Level

Easy3 of 10

Topics
String, Implementation, Math
Solved
No attempts yet

Problem

In this problem you must solve a very simple linear equation that has no parentheses and a single variable xx. An example of such an equation is:

2x-4+5x+300=98x

A general equation contains a = character with one expression on each side. Each expression is one or more terms combined by the + or - operator. Unary + or - operators are not allowed. Each term is either a single integer, an integer followed by the lower-case letter x, or the single character x (which is equivalent to 1x).

Write a program that finds the value of xx satisfying the equation. Note that the equation may have no solution or infinitely many solutions; your program must detect these cases as well.

Input

The first number tt (1≤t≤101 \le t \le 10) is the number of test cases, followed by tt lines, each containing one equation. Each line is at most 255 characters long. The equations contain no blank characters and the variable is always the lower-case letter x. The coefficients are integers in the range 00 to 10001000 inclusive.

Output

For each test case, print one line containing the solution of the equation. If ss is the solution, the output line must contain ⌊s⌋\lfloor s \rfloor (the floor of ss, i.e., the largest integer less than or equal to ss). Print IMPOSSIBLE if the equation has no solution, or IDENTITY if it has infinitely many solutions. The output is case-sensitive.

Examples3

  1. Example 1

    Input
    2
    2x-4+5x+300=98x
    x+2=2+x
    
    Expected output
    3
    IDENTITY
    
  2. Example 2

    Input
    5
    x=5
    2x+3=0
    x+1=x+2
    2x=2x
    1000x=1000
    
    Expected output
    5
    -2
    IMPOSSIBLE
    IDENTITY
    1
    
  3. Example 3

    Input
    4
    3x+1=0
    x+5=0
    x=0
    7x=3
    
    Expected output
    -1
    -5
    0
    0