#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 2011;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Result{
  int x, y, value;
  Result() {}
  Result(int v, int x, int y) : x(x), y(y), value(v) {}
};
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 a){
  int x, y;
  extgcd(a, MOD, x, y);
  return (MOD + x % MOD) % MOD;
}
int pow_mod(int a, int b) {
  int res = 1;
  int exp = a % MOD;
  while (b) {
    if (b & 1) res = (res * exp) % MOD;
    exp = (exp * exp) % MOD;
    b >>= 1;
  }
  return res;
}
Result expr(const vector<string>& grid, int x, int y);
Result term(const vector<string>& grid, int x, int y);
Result factor(const vector<string>& grid, int x, int y);
Result powexpr(const vector<string>& grid, int x, int y);
Result primary(const vector<string>& grid, int x, int y);
Result fraction(const vector<string>& grid, int x, int y);
Result expr(const vector<string>& grid, int x, int y){
  Result r = term(grid, x, y);
  while(grid[r.y].substr(r.x, 3) == ".+." || grid[r.y].substr(r.x, 3) == ".-."){
    Result r_ = term(grid, r.x + 3, r.y);
    if(grid[r.y][r.x + 1] == '+'){
      r.value = (r.value + r_.value) % MOD;
    }else{
      r.value = (r.value - r_.value + MOD) % MOD;
    }
    r.x = r_.x, r.y = r_.y;
  }
  return r;
}
Result term(const vector<string>& grid, int x, int y){
  //printf("term %d %d\n", x, y);
  Result r = factor(grid, x, y);
  while(grid[r.y].substr(r.x, 3) == ".*."){
    Result r_ = factor(grid, r.x + 3, r.y);
    r.value = (r.value * r_.value) % MOD;
    r.x = r_.x, r.y = r_.y;
  }
  return r;
}
Result factor(const vector<string>& grid, int x, int y){
  //printf("factor %d %d\n", x, y);
  if(grid[y].substr(x, 2) == "--"){
    //fraction
    return fraction(grid, x, y);
  }else if(grid[y].substr(x, 2) == "-."){
    //unary
    Result r = factor(grid, x + 2, y);
    r.value = (MOD - r.value) % MOD;
    return r;
  }else{
    //powexpr
    return powexpr(grid, x, y);
  }
}
Result powexpr(const vector<string>& grid, int x, int y){
  //printf("powexpr %d %d\n", x, y);
  Result r = primary(grid, x, y);
  if(r.y - 1 >= 0 && isdigit(grid[r.y - 1][r.x])){
    //pow
    int exp = grid[r.y - 1][r.x] - '0';
    r.value = pow_mod(r.value, exp);
    r.x++; // need???
    return r;
  }else{
    //primary
    return r;
  }
}
Result primary(const vector<string>& grid, int x, int y){
  //printf("primary %d %d\n", x, y);
  if(grid[y][x] == '('){
    Result r = expr(grid, x + 2, y);
    assert(grid[r.y][r.x] == '.');
    r.x++;
    assert(grid[r.y][r.x] == ')');
    r.x++;
    return r;
  }else if(isdigit(grid[y][x])){
    int v = grid[y][x] - '0';
    return Result(v, x + 1, y);
  }else {
    assert(false);
  }
}
Result fraction(const vector<string>& grid, int x, int y){
  Result r1, r2;
  for(int bx = x + 1; bx < (int)grid[0].size(); bx++){
    for(int by = y - 1; by >= 0; by--){
      if(grid[by][x] == '-') break;
      if(grid[by][bx] != '.'){
        r1 = expr(grid, bx, by);
        goto L1;
      }
    }
  }
L1:
  for(int bx = x + 1; bx < (int)grid[0].size(); bx++){
    for(int by = y + 1; by < (int)grid.size(); by++){
      if(grid[by][x] == '-') break;
      if(grid[by][bx] != '.'){
        r2 = expr(grid, bx, by);
        goto L2;
      }
    }
  }
L2:
  while(grid[y][x] == '-') x++;
  int v = (r1.value * inv_mod(r2.value)) % MOD;
  return Result(v, x, y);
}

int main(){
  int H;
  while(cin >> H && H){
    vector<string> grid(H);
    REP(i, H) cin >> grid[i];
    Result r;
    REP(y, H)if(grid[y][0] != '.') r = expr(grid, 0, y);
    cout << r.value << endl;
  }
  return 0;
}

Measured memory_bytes: 1232