#include<bits/stdc++.h>
using namespace std;
string S[111];
int id;
int N;
int L;

#define MOD (2011)

int Y[2012];
void init(){
  for(int i=0;i<2011;i++){
    for(int j=0;j<2011;j++){
      if( i * j % MOD == 1 ) Y[i] = j;
    }
  }
}
int expr(int top,int bottom);
int term(int top,int bottom);
int factor(int top,int bottom);
int powexpr(int top,int bottom);
int primary(int top,int bottom);
int fraction(int top,int bottom);
int digit(int top,int bottom);

int mod(int a,int m){
  //if( abs(a) < m ) return a;
  int ret = a%m;
  return ret<0?MOD+ret:ret;
}

int maxpow(int a,int b){
  int x = a;
  int ret = 1;
  while( b > 0 ){
    if( b & 1 ) ret = mod(ret*x,MOD);
    x = mod(x*x,MOD);
    b>>=1;
  }
  return ret;
}



int check(int top,int bottom,int index){
  while( index < L ){
    id = index;
    for(int i=top;i<=bottom;i++){
      if( S[i][index] != '.' ) return i;
    }
    ++index;
  }
  return -1;
}

void print(string s,int top,int bottom,int base){
  printf("%s top( %d ), bottom( %d ), base( %d ), id ( %d ), S[base][id]= %c \n\n",
	 s.c_str(),top,bottom,base,id,base==-1?'e':S[base][id]);
}

int expr(int top,int bottom) {
  int base = check(top,bottom,id); 
  //print("expr",top,bottom,base);
    if( base == -1 ) return 2012;
  int t = term(top,bottom);
  while(  id < L && S[base][id] == '.' ){
    int tmp_id = id;
    id++;
    if(  id < L && (S[base][id] == '+' || S[base][id] == '-') ){
      char op = S[base][id];
      id++;
      if(  id < L && S[base][id] == '.' ){
	id++;
	int r = term(top,bottom);
	//print("expr return",top,bottom,base);
	//printf(" t = %d , r = %d\n",t,r);
	if( op == '+' ) t += r;
	if( op == '-' ) t -= r;
	t = mod(t,MOD);
      } else {
	id = tmp_id;
	break;
      }
    } else {
      id = tmp_id;
      break;
    }
  }
  return t;
}
int term(int top,int bottom) {
  int base = check(top,bottom,id);
  //print("term",top,bottom,base);
    if( base == -1 ) return 2012;
  int t = factor(top,bottom);
  //print("term retrun",top,bottom,base);
  //printf("t = %d\n",t);
  while(  id < L && S[base][id] == '.' ){
    int tmp_id = id;
    id++;
    if( id < L && S[base][id] == '*' ){
      id++;
      if(  id < L && S[base][id] == '.' ){
	id++;
	int r = factor(top,bottom);
	//print("term multi retrun",top,bottom,base);
	//printf("t = %d\n",t);
	t = mod(t * r , MOD);
	//printf("r = %d t = %d\n",r,t);
      } else {
	id = tmp_id;
	break;
      }
    } else {
      id = tmp_id;
      break;
    }
  }
  return t;
}

int factor(int top,int bottom){
  int base = check(top,bottom,id);
 //print("factor",top,bottom,base);
   if( base == -1 ) return 2012;
  int tmp_id;
  int t=2012;
  bool f = false;
  tmp_id = id;
  t = powexpr(top,bottom);
  if( t > 2011 ) {
    id = tmp_id;
    t = fraction(top,bottom);
  }
  if( t > 2011 ) {
    id = tmp_id; 
    if( id+1 < L && S[base][id] == '-' && S[base][id+1] == '.'  ) {
      id +=2;
      f = true;
      t = factor(top,bottom);
    } 
  }
  if( f ) t *= -1;
  return mod(t,MOD); 
}
int powexpr(int top,int bottom){
  int base = check(top,bottom,id);
 //print("powexpr",top,bottom,base);
   if( base == -1 ) return 2012;
  int t = 2012;
  t = primary(top,bottom);
  if ( t == 2012 ) return 2012;
  if( id < L && base >0 && isdigit(S[base-1][id]) ){
    int r = digit(base-1,base-1);
    t = maxpow(t,r);
    //print("powexpr return ",top,bottom,base);
    //printf("t = %d\n",t);
  }
  return t;
}

int primary(int top,int bottom){
  int base = check(top,bottom,id);
 //print("primary",top,bottom,base);
   if( base == -1 ) return 2012;
  int tmp_id = id;
  int t = digit(top,bottom);
  if ( t == 2012 ){
    id = tmp_id;
    if( id+1 < L && S[base][id] == '(' && S[base][id+1] == '.' ){
      id += 2;
      t = expr(top,bottom);
      if( t == 2012 ) return 2012;
      //print("primary return",top,bottom,base);
      //printf("t = %d\n",t); 
      id +=2;
    } else {
      return t;
    }
  }
  return t;
}

int fraction(int top,int bottom){
  int base = check(top,bottom,id);
 //print("fraction",top,bottom,base);
  if( base == -1 ) return 2012;
  int t = 2012;
  if( id+2 < L && S[base][id] == '-' && S[base][id+1] == '-' && S[base][id+2] == '-'  ){
    id++;
    int tmp_id = id;
    int p = expr(top,base-1);
    id = tmp_id;
    if( p == 2012 ) return 2012;
    int q = expr(base+1,bottom);
    if( q == 2012 ) return 2012;
    id = max(id,tmp_id);
    while( id < L && S[base][id] == '-' ) id++;
    //print("fraction return",top,bottom,base);
    //printf("%d * Y[%d] = %d\n",p,q,Y[abs(q)]);
    t = mod(p*Y[abs(q)]*(q<0?-1:1),MOD);
  }
  return t;
}
int digit(int top,int bottom){
  int base = check( top,bottom,id );
 //print("digit",top,bottom,base);
 if( base == -1 ) return 2012;
  int t=0;
  bool f = false;
  while( id < L && isdigit(S[base][id]) ){
    f = true;
    t *= 10;
    t += S[base][id]-'0';
    id++;
  }
  if( f ) return mod(t,MOD);
  return 2012;
}



int main(){
  init();
  while( cin >> N && N ){
    for(int i=0;i<N;i++){
      cin >> S[i];
    }
    id = 0;
    L = (int)S[0].size();
    int res = mod(expr(0,N-1),MOD);
    if( res < 0 ) res = 2011+res;
    cout << res << endl;
  }
}

Measured memory_bytes: 1220