POCALC2  Modern Pocket Calculator
Adam likes pocket calculators, not only the early ones, but also the modern ones with a two line LCDdisplay and mathematically correct operator precedence. The upper (input)line shows the expression you typed in, the (output)line below shows the result immediately after the [=] key has been pressed. Given the calculator's inputline, the program's task is to produce its outputline. Using the calculator's [SD] key, the display switches between fractional and decimal representation of the result, so output must contain both representations.
Input
Input starts with a positive integer t (t<1000) in a single line, then t testcases follow. Every testcase consists of either three lines or a single line, representing the expression in the calculator's inputline, followed by a blank line. An expression contains n numbers (0 < n < 10) with exactly one operator (+, , x, :) between any two numbers and exactly one space to separate number and operator. There will be no invalid expression and no undefined operation.
A number is given as a decimal, a fraction or a mixed number and will be nonnegative. If a number is positive, its decimal value is between 10^{9} and 10^{9}, numerator and denominator are also nonnegative and not larger than 10^{9} each, given decimals have at most 9 digits overall. These constraints also hold for all calculations, if done properly. The length of the fraction bar depends on the maximum length of the numerator or the denominator respectively. If lengths of numerator and denominator are different, the shorter one will be centered based on the fraction bar. If centering isn't possible, it is set one digit to the right.
Output
For each testcase print the result the calculator will display in its outputline: first fractional, then decimal, both representations separated by " [SD] ". If a result is negative, the negative sign has to be printed directly (i.e. no space) in front of the integer part or the fraction bar.
The fractional representation has to be printed in lowest terms either as a proper fraction or mixed number. If the number has an integer representation, that has to be printed instead. Numerator and denominator have to be placed as described in the input section.
After " [SD] " the exact(!) decimal represenation has to be printed. As the screenshot shows, the calculator is even able to display a repeating decimal in its decimal representation using a vinculum, so that's what the program has to do as well, using underscores in the line above. You can assume that no decimal expansion is longer than 100 digits (it's a calculator with XXLdisplay).
The number of lines for every output depends on the result. It may be three lines (if fractions appear) or a single line (if result is an integer). Print a blank line after every testcase except the last one. Be careful not to print any trailing spaces.
For more clarity of input and output format please look at the examples below.
Example
Input:
5
9 50
2 + 0.26 x 
11 15
4 9
5.88   : 
18 5
3  5.125
9 + 14
1
 x 0.5
100
Output:
113 __
3 [SD] 3.684
165
1532 _________
5 [SD] 5.75654320987
2025
1
2 [SD] 2.125
8
23 [SD] 23
1
 [SD] 0.005
200
hide comments
Simes:
20191104 20:02:54
Here are a couple of test cases with 88 and 96 repeating digits


Petar Bosnjak:
20150528 00:13:59
I don't understand , do real numbers have at most 9 or 100 decimal digits? 

Nikola Samardzic:
20150526 18:26:39
1 1


Bartek Dudek:
20150522 23:24:26
@redmoon: maybe that will help:


redmoon:
20150522 11:49:58
Can the final result or mid calculation exceed 10^18? Last edit: 20150522 11:52:20 

jkelava6:
20150517 12:27:34
jkelava6: (edit) 20150517 12:27:34


PrzemysÅ‚aw Perkowski:
20150505 00:34:34
if the result is 1/63, should the program print 0.(015873) or 0.0(158730)?


Nikola Samardzic:
20150502 10:22:55
Are the numerators and denominators of fractions in input necessarily integers?

Added by:  numerix 
Date:  20110312 
Time limit:  0.200s 
Source limit:  10000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  own problem 