#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
using namespace std;

const int MOD = 2011;

#define DEBUG(x) cerr << #x << " = " << x << endl

int extgcd(int a, int b, int &x, int &y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  else {
    x = 1; y = 0;
  }
  return d;
}

int inv_mod(int value) {
  int x, y;
  extgcd(value, MOD, x, y);
  return (x % MOD + MOD) % MOD;
}

void mod_update(int &value) {
  value %= MOD;
  value += MOD;
  value %= MOD;
}

int H, W;
vector<string> S;
typedef pair<int, int> P;

P expr(int top, int bottom, int left, int right);
P term(int top, int bottom, int left, int right);
P factor(int top, int bottom, int left, int right);
P powexpr(int top, int bottom, int left, int right);

void show(int top, int bottom, int left, int right) {
  for(int i = top; i <= bottom; ++i) {
    for(int j = left; j <= right; ++j) {
      cerr << S[i][j];
    }
    cerr << endl;
  }
}

P expr(int top, int bottom, int left, int right) {
  // cerr << "expr(" << top << "," << bottom << "," << left << "," << right << ");" << endl;
  // show(top, bottom, left, right);
  P res = term(top, bottom, left, right);
  int ans = res.first;
  int p = res.second;
  while(p <= right) {
    char op = '\0';
    for(int i = top; i <= bottom; ++i) {
      if(S[i][p] == '+') op = '+';
      if(S[i][p] == '-') op = '-';
    }
    if(op == '\0') break;
    p += 2;
    P ret = term(top, bottom, p, right);
    if(op == '+') {
      ans += ret.first;
      mod_update(ans);
    }
    if(op == '-') {
      ans -= ret.first;
      mod_update(ans);
    }
    p = ret.second;
  }
  return make_pair(ans, p);
}

P term(int top, int bottom, int left, int right) {
  // cerr << "term(" << top << "," << bottom << "," << left << "," << right << ");" << endl;
  // show(top, bottom, left, right);
  P res = factor(top, bottom, left, right);
  int ans = res.first;
  int p = res.second;
  while(p <= right) {
    char op = '\0';
    for(int i = top; i <= bottom; ++i) {
      if(S[i][p] == '*') op = '*';
    }
    if(op == '\0') break;
    p += 2;
    P ret = factor(top, bottom, p, right);
    if(op == '*') {
      ans *= ret.first;
      mod_update(ans);
    }
    p = ret.second;
  }
  return make_pair(ans, p);
}

P factor(int top, int bottom, int left, int right) {
  // cerr << "factor(" << top << "," << bottom << "," << left << "," << right << ");" << endl;
  // show(top, bottom, left, right);
  char second = '\0';
  int baseline;
  for(int i = top; i <= bottom; ++i) {
    if(S[i][left] == '-' && S[i][left + 1] == '.') {
      second = '-';
    }
    if(S[i][left] == '-' && S[i][left + 1] == '-') {
      second = '/';
      baseline = i;
    }
  }

  if(second == '-') {
    P ret = factor(top, bottom, left + 2, right);
    ret.first *= -1;
    mod_update(ret.first);
    return ret;
  }

  if(second == '/') {
    int L = left;
    int R = left;
    while(S[baseline][R+1] == '-') R++;
    int l, r;

    l = L;
    while(true) {
      bool f = false;
      for(int i = top; i <= baseline - 1; ++i) {
        if(S[i][l] != '.')  f = true;
      }
      if(f) break;
      l++;
    }
    r = R;
    while(true) {
      bool f = false;
      for(int i = top; i <= baseline - 1; ++i) {
        if(S[i][r] != '.')  f = true;
      }
      if(f) break;
      r--;
    }

    P x = expr(top, baseline - 1, l, r);

    l = L;
    while(true) {
      bool f = false;
      for(int i = baseline + 1; i <= bottom; ++i) {
        if(S[i][l] != '.')  f = true;
      }
      if(f) break;
      l++;
    }
    r = R;
    while(true) {
      bool f = false;
      for(int i = baseline + 1; i <= bottom; ++i) {
        if(S[i][r] != '.')  f = true;
      }
      if(f) break;
      r--;
    }

    P y = expr(baseline + 1, bottom, l, r);
    int ret = x.first * inv_mod(y.first);
    mod_update(ret);
    return make_pair(ret, R + 2);
  }

  return powexpr(top, bottom, left, right);
}

P powexpr(int top, int bottom, int left, int right) {
  // cerr << "powexpr(" << top << "," << bottom << "," << left << "," << right << ");" << endl;
  // show(top, bottom, left, right);
  P p;
  int primary;
  int baseline;
  char op = '\0';
  for(int i = top; i <= bottom; ++i) {
    if(S[i][left] == '(') {
      op = '(';
      baseline = i;
    }
    if(isdigit(S[i][left])) {
      op = S[i][left];
      baseline = i;
    }
  }
  if(op == '(') {
    p = expr(top, bottom, left + 2, right);
    p.second += 1; // skip ' ' ')'
    primary = p.first;
  }
  else {
    p = make_pair(S[baseline][left] - '0', left + 1);
    primary = p.first;
  }

  if(p.second <= right && top <= baseline - 1) {
    char c = S[baseline - 1][p.second];

    if(isdigit(c)) {
      int ret = 1;
      for(int i = 0; i < c - '0'; ++i) {
        ret *= primary;
        mod_update(ret);
      }
      p = make_pair(ret, p.second + 1);
    }
  }

  p.second += 1;
  return p;
}

int main() {
  while(true) {
    cin >> H;
    if(H == 0) break;
    S.resize(H);
    for(int i = 0; i < H; ++i) {
      cin >> S[i];
    }
    W = S.begin()->size();
    P ans = expr(0, H - 1, 0, W - 1);
    cout << ans.first << endl;
  }
}

Measured memory_bytes: 1224