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

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        while (n-- > 0)
        {
            var s = Console.ReadLine().Trim();
            var res = conv3(s);
            var q = conv2(res);
            var ans = getAns(q);
            Console.WriteLine(ans);
        }
    }
    static int getAns(Queue<string> q)
    {
        var st = new Stack<int>();
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w == "+")
            {
                var t = st.Pop() + st.Pop();
                st.Push(t);
            }
            else if (w == "-")
            {
                var t = -st.Pop() + st.Pop();
                st.Push(t);
            }
            else if (w == "*")
            {
                var t = st.Pop() * st.Pop();
                st.Push(t);
            }
            else if (w == "/")
            {
                var a1 = st.Pop();
                var a2 = st.Pop();
                var t = a2 / a1;
                st.Push(t);
            }
            else st.Push(int.Parse(w));
        }
        return st.Pop();
    }

    static Queue<string> conv2(List<string> line)
    {
        var q = new Queue<string>();
        var st = new Stack<string>();
        foreach (var x in line)
        {
            if (x == "(") st.Push(x);
            else if (x == "+" | x == "-")
            {
                if (st.Count() == 0) st.Push(x);
                else
                {
                    if (st.Peek() == "*" | st.Peek() == "/")
                    {
                        q.Enqueue(st.Pop());
                        if (st.Count() > 0 && (st.Peek() == "+" | st.Peek() == "-")) q.Enqueue(st.Pop());
                        st.Push(x);
                    }
                    else if (st.Peek() == "+" | st.Peek() == "-")
                    {
                        q.Enqueue(st.Pop());
                        st.Push(x);
                    }
                    else if (st.Peek() == "(") { st.Push(x); }
                }
            }
            else if (x == "*" | x == "/")
            {
                if (st.Count() == 0) st.Push(x);
                else
                {
                    if (st.Peek() == "*" | st.Peek() == "/")
                    { q.Enqueue(st.Pop()); st.Push(x); }
                    else if (st.Peek() == "+" | st.Peek() == "-")
                    { st.Push(x); }
                    else if (st.Peek() == "(") { st.Push(x); }
                }
            }
            else if (x == ")")
            {
                while (true)
                {
                    if (st.Peek() == "(") { st.Pop(); break; }
                    else q.Enqueue(st.Pop());
                }
            }
            else q.Enqueue(x);
        }
        while (st.Count() > 0)
        {
            q.Enqueue(st.Pop());
        }
        return q;
    }
    static List<string> conv3(string s)
    {
        var res = new List<string>();
        var sL = s.Length;
        var flag = false;
        var nn = "";
        for (int i = 0; i < sL; i++)
        {
            var w = s.Substring(i, 1);
            if (w == "*" | w == "/" | w == "+" | w == "-" | w == "(" | w == ")")
            {
                if (flag) { res.Add(nn); nn = ""; flag = false; }
                res.Add(w);
            }
            else if (w == "=" && flag) res.Add(nn);
            else { nn += w; flag = true; }
        }
        return res;
    }
}


Measured memory_bytes: 14396