// Generated by CoffeeScript 1.3.3
(function() {
  var a=[];
  var stdin = process.openStdin();
  stdin.setEncoding('utf8');

  var proc = function(s) {
    var bidx, count, eidx, m;
    bidx = s.indexOf('(');
    while (bidx !== -1) {
      count = 1;
      eidx = bidx + 1;
      while (count > 0) {
        if (s[eidx] === '(') {
          count++;
        }
        if (s[eidx] === ')') {
          count--;
        }
        eidx++;
      }
      s = s.substring(0, bidx) + proc(s.substring(bidx + 1, eidx - 1)) + s.substring(eidx);
      bidx = s.indexOf('(');
    }
    while ((m = /^(.*?)(-?\d+)([*/])(-?\d+)(.*)$/.exec(s)) != null) {
      if (m[3] === '*') {
        s = m[1] + (parseInt(m[2]) * parseInt(m[4])) + m[5];
      } else {
        s = m[1] + (parseInt(m[2]) / parseInt(m[4]) ^ 0) + m[5];
      }
    }
    while ((m = /^(.*?)(-?\d+)([+Z])(-?\d+)(.*)$/.exec(s)) != null) {
      if (m[3] === '+') {
        s = m[1] + (parseInt(m[2]) + parseInt(m[4])) + m[5];
      } else {
        s = m[1] + (parseInt(m[2]) - parseInt(m[4])) + m[5];
      }
    }
    return s;
  };

  stdin.on('data', function(input) {
    var e, x;
    x = (function() {
      var _i, _len, _ref, _results;
      _ref = input.split("\n");
      _results = [];
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        e = _ref[_i];
        _results.push(e);
      }
      return _results;
    })();
    if (x.length > 2 || !isNaN(x[1])) {
      return a = x;
    } else {
      return a.push(x[0]);
    }
  });

  stdin.on('end', function(z) {
    var i, n, s, _i, _results;
    n = parseInt(a[0]);
    _results = [];
    for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {
      s = a[i].substring(0, a[i].indexOf('=')).replace(/-/g, 'Z');
      _results.push(console.log(proc(s)));
    }
    return _results;
  });

}).call(this);