#P1572. Fraction Arithmetic

    ID: 14858 Type: Default 1000ms 256MiB

Fraction Arithmetic

Fraction Arithmetic

Csh has been forced by his mother to solve a series of fraction arithmetic problems at home. However, he would rather go watch a movie with Xxq, who is waiting outside. To help him get out faster, you are tasked with solving these problems.

You are given an arithmetic expression that involves two fractions in the form \(\frac{a}{b}\) and an operator. The operator can be one of the following: addition (\( + \)), subtraction (\( - \)), multiplication (\( \times \)), or division (\( \div \)). Compute the result of the arithmetic operation and output the result as a simplified (irreducible) fraction \(\frac{p}{q}\).

Note: If the computed fraction is negative, the negative sign should appear in the numerator.

inputFormat

The first line of input contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains an arithmetic expression in the format:

\(a/b \; op \; c/d\)

where \(a, b, c, d\) are integers (with \(b\) and \(d\) nonzero) and op is one of the four operators: +, -, *, or /.

outputFormat

For each test case, output the result as a simplified (irreducible) fraction in the format \(p/q\) on a new line.

sample

1
1/2 + 1/3
5/6

</p>