#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <vector>
#include <string>

#define fprintf(...) void(0)

constexpr intmax_t MOD=2011;

intmax_t apply(intmax_t lhs, char op, intmax_t rhs) {
  switch (op) {
  case '+': return (lhs + rhs) % MOD;
  case '-': return ((lhs - rhs) % MOD + MOD) % MOD;
  case '*': return (lhs * rhs) % MOD;
  }
  assert(false);
}

intmax_t modpow(intmax_t base, intmax_t iexp) {
  fprintf(stderr, "%jd^%jd\n", base, iexp);
  intmax_t res=1;
  for (intmax_t dbl=base; iexp; iexp>>=1) {
    if (iexp & 1) (res *= dbl) %= MOD;
    (dbl *= dbl) %= MOD;
  }
  return res;
}

intmax_t moddiv(intmax_t num, intmax_t den) {
  intmax_t div=modpow(den, MOD-2);
  return num*div % MOD;
}

intmax_t parse(const std::vector<std::string> &s, size_t &i,
               size_t top, size_t bottom, size_t left, size_t right,
               size_t preced=0, size_t base=-1,
               const std::vector<std::string> &ops={"+-", "*"}) {

  while (base+1 == 0) {
    for (size_t r=top; r<bottom; ++r) {
      if (s[r][i] != '.') {
        base = r;
        break;
      }
    }
    if (base+1 == 0) ++i;
  }
  assert(base+1 != 0);
  fprintf(stderr, "s[%zu][%zu]: LR[%zu, %zu), TB[%zu, %zu), prec:%zu\n",
          base, i, left, right, top, bottom, preced);

  if (preced == ops.size()) {
    intmax_t res=114514;
    if (s[base][i] == '(') {
      res = parse(s, i+=2, top, bottom, left, right, 0, base);
      fprintf(stderr, "s[%zu][%zu] L%d\n", base, i, __LINE__);
      assert(s[base][i] == ')');
      ++i;
    } else if (s[base][i] == '-') {
      if (s[base][i+1] == '-') {
        size_t vl=i, vr=i+1;
        while (s[base][++vr] == '-') {}

        size_t j=vl+1;
        intmax_t numer=parse(s, j, top, base, vl, vr, 0);
        j = vl+1;
        intmax_t denom=parse(s, j, base+1, bottom, vl, vr, 0);
        res = moddiv(numer, denom);
        i = vr;
      } else {
        res = MOD-parse(s, i+=2, top, bottom, left, right, preced, base);
        return res;  // ???
      }
    } else if (isdigit(s[base][i])) {
      res = s[base][i]-'0';
      ++i;
    } else {
      fprintf(stderr, "s[%zu][%zu] on L%d\n", base, i, __LINE__);
      assert(false);
    }

    if (i < right && top+1 <= base && isdigit(s[base-1][i])) {
      fprintf(stderr, "s[%zu][%zu]: %c\n", base-1, i, s[base-1][i]);
      fprintf(stderr, "%jd^%jd: L%d\n", res, intmax_t(s[base-1][i]-'0'), __LINE__);
      res = modpow(res, s[base-1][i]-'0');
      ++i;
    }
    ++i;
    fprintf(stderr, "s[%zu][%zu]\n", base, i);
    fprintf(stderr, "Returns %jd\n", res);
    return res;
  }

  intmax_t lhs=parse(s, i, top, bottom, left, right, preced+1, base);
  while (i < right) {
    char op=s[base][i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    intmax_t rhs=parse(s, i+=2, top, bottom, left, right, preced+1, base);
    lhs = apply(lhs, op, rhs);
  }
  return lhs;
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<std::string> s;
  for (size_t i=0; i<n; ++i) {
    char buf[128];
    scanf("%s", buf);
    s.emplace_back(buf);
  }

  size_t i=0;
  intmax_t res=parse(s, i, 0, s.size(), 0, s[0].length());
  printf("%jd\n", res);
  fprintf(stderr, "------------------------------\n");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}


Measured memory_bytes: 2808