// Arup Guha
// 7/10/07
// Fraction class for 2007 BHCSI: this class manages a fraction object.

// Edited for 2007 BHCSI Week #1 Programming Contest Problem Fraction

import java.util.*;
import java.io.*;

public class fraction {

  	private int numerator;
  	private int denominator;

	// Creates a fraction object with the value n/d.
  	public fraction(int n, int d) {
		numerator = n;
    	denominator = d;
    	reduce();
    	
		// Helps us deal with the value undefined.    	
    	if (denominator == 0)
    		numerator = 1;
  	}

	// This method is only used within the class and simply reduces
	// the current object to lowest terms.
  	private void reduce() {
		int common = gcd(numerator, denominator);
     	numerator /= common;
     	denominator /= common;
     	
     	// Standard mathematical convention is to maintain a positive 
     	// denominator.
     	if (denominator < 0) {
     		numerator = -numerator;
     		denominator = -denominator;
     	}
     	
  	}

	// Computes the greatest common divisor of a and b.
	// Note: This is not an efficient implementation of this method.
	//       The typical implementation is recursive, but recursion
	//       has not been taught in the class that this example is
	// 		 for.
  	private static int gcd(int a, int b) {
  		
  		// If we get negative values, we have to properly deal with them. The
  		// standard algorithm assumes positive values, so we just take the
  		// absolute value of our inputs.
  		if (a < 0) a = -a;
  		if (b < 0) b = -b;
  		
    	int answer = 1;
    	
    	// Try out successively larger factors, and store new
    	// factors of both numbers whenever one is found.
    	for (int i=2; i<=a && i<=b; i++) {
    		if (a%i == 0 && b%i == 0)
    			answer = i;
    	}
    	
    	return answer;
  	}
  	
  	// Adds the current fraction object to f and returns the result as
  	// another fraction object.
  	public fraction add(fraction f) {
  		
  		// Get the standard common denominator and calculate the
  		// corresponding numerator.
  		int num = this.numerator*f.denominator + this.denominator*f.numerator;
  		int den = this.denominator*f.denominator;
  	
  		// Create the new object and return it.
  		return new fraction(num, den);
  	}
  	
  	public fraction subtract(fraction f) {
  		// Get the standard common denominator and calculate the
  		// corresponding numerator.
  		int num = this.numerator*f.denominator - this.denominator*f.numerator;
  		int den = this.denominator*f.denominator;
  	
  		// Create the new object and return it.
  		return new fraction(num, den);
  	}
  	
  	public fraction multiply(fraction f) {
  		
  		// This calculation is fairly straight-forward.
  		int num = this.numerator*f.numerator;
  		int den = this.denominator*f.denominator;
  		
  		return new fraction(num, den);
  	}
  	
  	public fraction divide(fraction f) {
  	
  		// This calculation sometimes confuses people, but we just
  		// flip the location of both pieces of the divider.
  		int num = this.numerator*f.denominator;
  		int den = this.denominator*f.numerator;
  		
  		return new fraction(num, den);
  	}
  	
  	// Returns a String representation of the current object.
  	public String toString() {
  		return numerator+"/"+denominator;
  	}
  	
  	public static void main(String[] args) throws IOException {
  		
  		Scanner fin = new Scanner(new File("fraction.in"));
  		
  		int numcases = fin.nextInt();
  		
  		// Loop through each case individually.
  		for (int i=1; i<=numcases; i++) {
  			
  			int numterms = fin.nextInt();
  			
  			// Read in the first term and set up the initial fraction object.
  			int num = fin.nextInt();
  			int den = fin.nextInt();
  			fraction answer = new fraction(num, den);
  			
  			// Loop throug the rest of the terms.
  			for (int j=1; j<numterms; j++) {
  			
  				// First obtain the operator
  				String ans = fin.next();
  				char operand = ans.charAt(0);
  				
  				// Obtain the next operand.
  				num = fin.nextInt();
  				den = fin.nextInt();
  				fraction tmp = new fraction(num, den);
  				
  				// Carry out the appropriate action and store the result.
  				if (operand == '+')
 					answer = answer.add(tmp);
 				else if (operand == '-')
 					answer = answer.subtract(tmp);
 				else if (operand == '*')
 					answer = answer.multiply(tmp);
 				else 
 					answer = answer.divide(tmp);	
  			}
  			
  			// Output for this case.
  			System.out.println("Answer to Problem #"+i+" = "+answer);
  		}
  		
  		fin.close();
  	}
}
