


An irreducible fraction is a fraction in which the numerator and denominator are integers that have no other common divisors than 1.
Example: 2/3, 8/9, 0/1 are irreducible fractions, where 8/12, 9/12 are not irreducible fractions.
Ayush expects your answer to be an irreducible fraction, so if your answer is an integer, convert it into an irreducible fraction by putting 1 in the denominator.
For example, if your answer is "9", then print "9/1" (without quotes).
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains a string ‘EXPRESSION’, representing the expression that you need to solve.
The input only contains valid irreducible fractions, where the numerator and denominator of each fraction will always be in the range [1,10].
For each test case, return the irreducible fraction after solving the expression.
Output for each test case is printed on a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= |EXPRESSION| <= 10^5
‘EXPRESSION’ will only contain integers from '0' to '9', and characters '/', '+' and '-'.
Time Limit: 1 sec
We can use brute force to solve the problem. We can simplify this problem by making all denominators equal. This can be done by finding the least common multiple of all the denominators.
First, store the fractions in an array. Then, rewrite the expression such that each fraction will have a common denominator. Now, expression can be easily solved by only solving all the numerators. After that, convert the final expression into an irreducible fraction.
We can solve this problem as we iterate over ‘EXPRESSION’ and solve the fractions sequentially. To do this we need to maintain the overall result in the form of X / Y.
For each fraction part in the form of A / B, where A is the numerator and B is the denominator. Here we are solving X / Y + A / B so after taking LCM, the result will be (X * B + Y * A) / Y * B. Convert it into an irreducible fraction by removing the common divisor.