using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

static class SmartCalculator
{
   private class EquationNode
   {
      public EquationNode left;
      public EquationNode right;

      public int value { get { return GetValue(this); } }
      public Func<EquationNode, int> GetValue;

      public static EquationNode Constant(int value)
      {
         return new EquationNode{ GetValue = x => value };
      }
      public static EquationNode ReferenceRight()
      {
         return new EquationNode{ GetValue = x => x.right.value };
      }
   }

   public static int Calculate(string equation)
   {
      return MakeTree(equation).value;
   }

   private static EquationNode MakeTree(string equation)
   {
      var root = EquationNode.ReferenceRight();
      root.right = EquationNode.ReferenceRight();
      var node = root;

      EquationNode valueNode = null;
      for (int index = 0; index < equation.Length; index++)
      {
         char word = equation[index];
         switch (word)
         {
            case '+':
               node.right.right = valueNode;
               root = new EquationNode
               {
                  left = root,
                  right = EquationNode.ReferenceRight(),
                  GetValue = x => x.left.value + x.right.value,
               };
               node = root;
               break;
            case '-':
               node.right.right = valueNode;
               root = new EquationNode
               {
                  left = root,
                  right = EquationNode.ReferenceRight(),
                  GetValue = x => x.left.value - x.right.value,
               };
               node = root;
               break;
            case '*':
               node.right.right = valueNode;
               node.right = new EquationNode
               {
                  left = node.right,
                  GetValue = x => x.left.value * x.right.value,
               };
               break;
            case '/':
               node.right.right = valueNode;
               node.right = new EquationNode
               {
                  left = node.right,
                  GetValue = x => x.left.value / x.right.value,
               };
               break;
            case '(':
               {
                  int nest = 1;
                  int end;
                  for (end = index + 1; nest > 0; end++)
                  {
                     switch (equation[end])
                     {
                        case '(':
                           nest++;
                           break;
                        case ')':
                           nest--;
                           break;
                     }
                  }
                  var innerEquation = equation.Substring(index + 1, (end - 1) - (index + 1));
                  valueNode = MakeTree(innerEquation);
                  index = end - 1;
                  break;
               }
            default:
               // 数値
               {
                  var end = index;
                  while (end < equation.Length && '0' <= equation[end] && equation[end] <= '9')
                  {
                     end++;
                  }
                  var innerEquation = equation.Substring(index, end - index);
                  int value = int.Parse(innerEquation);
                  valueNode = EquationNode.Constant(value);
                  index = end - 1;
                  break;
               }
         }
      }

      node.right.right = valueNode;

      return root;
   }
}

class MainClass
{
   static void Main(string[] args)
   {
      var stringBuilder = new StringBuilder();

      int n = int.Parse(Console.ReadLine());
      for (; n > 0; n--)
      {
         var equation = Console.ReadLine().TrimEnd('=');
         var result = SmartCalculator.Calculate(equation);

         stringBuilder.AppendLine(result.ToString());
      }

      Console.Write(stringBuilder.ToString());
   }
}


Measured memory_bytes: 9380