#!/usr/bin/env python
#
# This solution performs all addition and subtraction with Python ints/longs;
# longs have no size limit.

__author__ = 'Matt Eastman'

import string


class CrazyInt(object):
  _charset = string.digits + string.uppercase
  _max = 0  # replaced after class definition

  def __init__(self, value):
    self._valid = True
    if value is None:
      self._valid = False
    elif isinstance(value, str):
      self._value = 0
      negative = value.startswith('-')
      if negative:
        value = value[1:]
      if len(value) >= 36:
        self._valid = False
        return
      base = len(value) + 1
      for c in value:
        digit = self._charset.find(c)
        if digit >= base:
          self._valid = False
          return
        self._value = self._value * base + digit
        base -= 1
      if negative:
        self._value *= -1
    elif isinstance(value, (int, long)):
      self._value = value
      if abs(value) > self._max:
        self._valid = False
    elif isinstance(value, CrazyInt):
      self._value = value._value
      self._valid = value._valid
    else:
      raise TypeError()

  def __str__(self):
    if not self._valid:
      return 'Invalid'
    if self._value < 0:
      return '-' + str(CrazyInt(-self._value))
    out = []
    n = self._value
    while n:
      digit_base = len(out) + 2
      n, i = divmod(n, digit_base)
      out.insert(0, self._charset[i])
    if not out:
      out.append('0')
    return ''.join(out)

  def __add__(self, other):
    if not (self._valid and other._valid):
      return CrazyInt(None)
    return CrazyInt(self._value + other._value)

  def __sub__(self, other):
    if not (self._valid and other._valid):
      return CrazyInt(None)
    return CrazyInt(self._value - other._value)

  def __neg__(self):
    if not self._valid:
      return CrazyInt(self)
    return CrazyInt(-self._value)

CrazyInt._max = CrazyInt(CrazyInt._charset[1:][::-1])._value


def main():
  for _ in xrange(input()):
    pieces = raw_input().split()
    assert len(pieces) == 3
    a = CrazyInt(pieces[0])
    b = CrazyInt(pieces[2])
    op = pieces[1]
    result = CrazyInt(None)
    if op == '+': result = a + b
    elif op == '-': result = a - b
    print result

if __name__ == '__main__':
  main()
