#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 2011
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 mod_inverse(int a,int m){
  int x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}
int mod_pow(int x,int n,int mod){
  int res=1;
  while(n>0){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}
int n;
string str[30];
int expr(int top,int bottom,int& p);
int term(int top,int bottom,int& p);
int factor(int top,int bottom,int& p);
int powexpr(int top,int bottom,int& p);
int primary(int top,int bottom,int& p);
int fraction(int top,int bottom,int& p);
int digit(int top,int bottom,int& p);

bool dbg=0;

int expr(int top,int bottom,int& p){
  int base;
  while(p<(int)str[0].size()){
    bool f=0;
    for(int i=top;i<bottom;i++)
      if(str[i][p]!='.') base=i,f=1;
    if(!f) p++;
    else break;
  }
  if(dbg){
    cout<<"expr"<<endl;
    for(int i=top;i<bottom;i++)
      cout<<str[i]<<endl;
    cout<<endl;
  }
  int res=term(top,bottom,p);
  while(p+1<(int)str[base].size()){
    //cout<<"p+1:"<<str[base][p+1]<<endl;
    if(str[base][p+1]=='+'){
      p+=3;
      (res+=term(top,bottom,p))%=MOD;
      continue;
    }
    if(str[base][p+1]=='-'){
      p+=3;
      (res+=MOD-term(top,bottom,p))%=MOD;
      continue;
    }
    break;
  }
  if(dbg) cout<<"expr:"<<p<<" "<<res<<endl;
  return res;
}

int term(int top,int bottom,int& p){
  int base;
  while(p<(int)str[0].size()){
    bool f=0;
    for(int i=top;i<bottom;i++)
      if(str[i][p]!='.') base=i,f=1;
    if(!f) p++;
    else break;
  }
  int res=factor(top,bottom,p);
  while(p+1<(int)str[base].size()){
    if(str[base][p+1]=='*'){
      p+=3;
      (res*=factor(top,bottom,p))%=MOD;
      continue;
    }
    break;
  }
  if(dbg) cout<<"term:"<<p<<" "<<res<<endl;
  return res;
}

int factor(int top,int bottom,int& p){
  int base;
  while(p<(int)str[0].size()){
    bool f=0;
    for(int i=top;i<bottom;i++)
      if(str[i][p]!='.') base=i,f=1;
    if(!f) p++;
    else break;
  }
  int res;
  if(str[base][p]=='-'){
    if(str[base][p+1]=='-'){
      res=fraction(top,bottom,p);
    }else if(str[base][p+1]=='.'){
      p+=2;
      res=(MOD-factor(top,bottom,p))%MOD;
    }
  }else{
    res=powexpr(top,bottom,p);
  }
  if(dbg) cout<<"factor:"<<p<<" "<<res<<endl;
  return res;
}

int powexpr(int top,int bottom,int& p){
  int base;
  while(p<(int)str[0].size()){
    bool f=0;
    for(int i=top;i<bottom;i++)
      if(str[i][p]!='.') base=i,f=1;
    if(!f) p++;
    else break;
  }
  int res=primary(top,bottom,p);
  if(p<(int)str[0].size()&&base>0){
    if(isdigit(str[base-1][p])){
      res=mod_pow(res,str[base-1][p]-'0',MOD);
      p++;
    }
  }
  if(dbg) cout<<"powexpr:"<<p<<" "<<res<<endl;
  return res;
}
int primary(int top,int bottom,int& p){
  int base;
  while(p<(int)str[0].size()){
    bool f=0;
    for(int i=top;i<bottom;i++)
      if(str[i][p]!='.') base=i,f=1;
    if(!f) p++;
    else break;
  }
  int res;
  if(str[base][p]=='('){
    p+=2;
    res=expr(top,bottom,p);
    p+=2;
  }else{
    res=str[base][p++]-'0';
  }
  if(dbg) cout<<"primary:"<<p<<" "<<res<<endl;
  return res;
}
int fraction(int top,int bottom,int& p){
  int base;
  while(p<(int)str[0].size()){
    bool f=0;
    for(int i=top;i<bottom;i++)
      if(str[i][p]!='.') base=i,f=1;
    if(!f) p++;
    else break;
  }
  int q=p+1;
  int res=expr(top,base,q);
  q=p+1;
  (res*=mod_inverse(expr(base+1,bottom,q),MOD))%=MOD;
  while(str[base][p]=='-') p++;
  if(dbg) cout<<"fraction:"<<p<<" "<<res<<endl;
  return res;
}
signed main(){
  while(cin>>n,n){
    for(int i=0;i<30;i++) str[i]="";
    for(int i=0;i<n;i++) cin>>str[i];
    int p=0;
    cout<<expr(0,n,p)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084