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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine();
                string formula = input.Replace("=", "");

                Stack<int> leftIndex = new Stack<int>();

                for (int j = 0; j < formula.Length; j++)
                {
                    if (formula[j] == '(')
                    {
                        leftIndex.Push(j);
                    }
                    else if (formula[j] == ')')
                    {
                        int idx = leftIndex.Pop();

                        string subStrA = formula.Substring(idx, j - idx + 1);
                        string subStrB = formula.Substring(idx + 1, j - idx - 1);

                        formula = formula.Replace(subStrA, Calc(subStrB));
                        j = idx;
                    }
                }
                sb.AppendLine(Calc(formula));
            }
            Console.Write(sb);
        }

        static string Calc(string formula)
        {
            List<string> fl1 = new List<string>();

            string num = "";

            for (int i = 0; i < formula.Length; i++)
            {
                switch (formula[i])
                {
                    case '+':
                        if (num != "")
                        {
                            fl1.Add(num);
                            num = "";
                        }
                        break;
                    case '-':
                        if (num != "")
                        {
                            fl1.Add(num);
                            num = "";
                        }
                        num += formula[i];
                        break;
                    case '*':
                        fl1.Add(num);
                        num = "";
                        fl1.Add(formula[i].ToString());
                        break;
                    case '/':
                        fl1.Add(num);
                        num = "";
                        fl1.Add(formula[i].ToString());
                        break;
                    default:
                        num += formula[i];
                        break;
                }
            }
            if (num != "") fl1.Add(num);

            List<int> fl2 = new List<int>();

            for (int i = 0; i < fl1.Count; i++)
            {
                switch (fl1[i])
                {
                    case "*":
                        fl2[fl2.Count - 1] *= int.Parse(fl1[i + 1]);
                        i++;
                        break;
                    case "/":
                        fl2[fl2.Count - 1] /= int.Parse(fl1[i + 1]);
                        i++;
                        break;
                    default:
                        fl2.Add(int.Parse(fl1[i]));
                        break;
                }
            }
            return fl2.Sum().ToString();
        }
    }
}

Measured memory_bytes: 10420