#include<bits/stdc++.h>

using namespace std;

const int mod = 2011;

typedef long long int64;

int expr(int, int, int);

inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

inline int64 modInv(int64 a)
{
  return (modPow(a, mod - 2));
}

int N, idx, width;
string S[20];

int LatteMalta(int top, int bottom)
{
  while(idx < width) {
    for(int i = top; i < bottom; i++) {
      if(S[i][idx] != '.') return (i);
    }
    ++idx;
  }
  return (-1);
}

int primary(int base, int top, int bottom)
{
  if(S[base][idx] == '(') {
    idx += 2;
    auto get = expr(base, top, bottom);
    idx += 2;
    return (get);
  } else {
    return (S[base][idx++] - '0');
  }
}

int powexpr(int base, int top, int bottom)
{
  int ret = primary(base, top, bottom);
  if(top <= base - 1 && idx < width && isdigit(S[base - 1][idx])) {
    return (modPow(ret, S[base - 1][idx++] - '0'));
  } else {
    return (ret);
  }
}

int factor(int base, int top, int bottom)
{
  if(S[base][idx] == '-' && S[base][idx + 1] == '.') {
    idx += 2;
    return ((mod - factor(base, top, bottom)) % mod);
  } else if(S[base][idx] == '-') {
    int latte = idx;
    auto ue = expr(LatteMalta(top, base), top, base);
    idx = latte;
    auto sita = expr(LatteMalta(base + 1, bottom), base + 1, bottom);
    idx = latte;
    while(idx < width && S[base][idx] == '-') ++idx;
    return (ue * modInv(sita) % mod);
  } else {
    return (powexpr(base, top, bottom));
  }
}

int term(int base, int top, int bottom)
{
  int ret = factor(base, top, bottom);
  while(idx + 2 < width && S[base][idx] == '.' && S[base][idx + 1] == '*') {
    idx += 3;
    (ret *= factor(base, top, bottom)) %= mod;
  }
  return (ret);
}

int expr(int base, int top, int bottom)
{
  int ret = term(base, top, bottom);
  while(idx + 2 < width && S[base][idx] == '.' && (S[base][idx + 1] == '+' || S[base][idx + 1] == '-')) {
    char operation = S[base][idx + 1];
    idx += 3;
    auto get = term(base, top, bottom);
    if(operation == '+') (ret += get) %= mod;
    else (ret += mod - get) %= mod;
  }
  return (ret);
}

int main()
{
  while(cin >> N, N) {
    for(int i = 0; i < N; i++) cin >> S[i];
    idx = 0;
    width = (int) S[0].size();
    cout << expr(LatteMalta(0, N), 0, N) << endl;
  }

}