#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;

const int MAX_H = 20;
const int MAX_W = 160;
const int MOD = 2011;

#ifndef DBG
#define DBG 0
#endif

int H, W;
int d; //ツデツバツッツグツ用
int inv[MOD];
char str[MAX_H][MAX_W+1];

int expr(int y1, int x1, int y2, int x2, int& p);
int term(int y1, int x1, int y2, int x2, int& p);
int factor(int y1, int x1, int y2, int x2, int& p);
int powexp(int y1, int x1, int y2, int x2, int& p);
int primary(int y1, int x1, int y2, int x2, int& p);
int fraction(int y1, int x1, int y2, int x2, int& p);
int digit(int y1, int x1, int y2, int x2, int& p);

int pow_calc(int x, int n){
	int ret = 1;
	for(;n;n>>=1){
		if(n&1){
			ret = ret * x % MOD;
		}
		x = x * x % MOD;
	}
	
	return ret;
}

//ツつキツづ猟づЪy1, y2) * [x1,x2)ツづ個陛つ凝ヲツ甘板づ考ツつヲツづゥ!!!!!!
int cut(int& y1, int& x1, int& y2, int& x2){

	int line = -1;
	//ツ債カツづーツカツッツト
	for(;;){
		bool found = false;
		for(int i=y1; i<y2; i++){
			if(str[i][x1] != '.'){
				found = true;
				line = i;
			}	
		}
		if(!found){
			x1++;
		}
		else{
			break;
		}
	}
	
	//ツ右ツづーツカツッツト
	for(;;){
		bool found = false;
		for(int i=y1; i<y2; i++){
			if(str[i][x2-1] != '.'){
				found = true;
			}	
		}
		if(!found){
			x2--;
		}
		else{
			break;
		}
	}
	//ツ湘」ツづーツカツッツト
	for(;;){
		bool found = false;
		for(int i=x1; i<x2; i++){
			if(str[y1][i] != '.'){
				found = true;
			}	
		}
		if(!found){
			y1++;
		}
		else{
			break;
		}
	}
	//ツ可コツづーツカツッツト
	for(;;){
		bool found = false;
		for(int i=x1; i<x2; i++){
			if(str[y2-1][i] != '.'){
				found = true;
			}	
		}
		if(!found){
			y2--;
		}
		else{
			break;
		}
	}
	
	return line;
}

void dbg(const char* s){
	if(DBG){
		for(int i=0; i<d; i++) putchar(' ');
		puts(s);
	}
}

int expr(int y1, int  x1, int y2, int x2, int& p){
	dbg("expr in"); d++;
	int line = cut(y1, x1, y2, x2), ret = -1;
	p = x1;
	
	ret = term(y1, x1, y2, x2, p);
	while( p + 3 < x2 && (str[line][p+1]=='+' || str[line][p+1]=='-') ){
		p += 3;
		ret = (ret + (str[line][p-2]=='+' ? 1 : -1) * term(y1, p, y2, x2, p) + MOD) % MOD;
	}
	
	d--; dbg("expr out");
	return ret;
}

int term(int y1, int x1, int y2, int x2, int& p){
	dbg("term in:"); d++;
	int line = cut(y1, x1, y2, x2);
	p = x1;
	int ret = factor(y1, x1, y2, x2, p);

	while( p + 3 < x2 && str[line][p+1] == '*' ){
		p += 3;
		ret = ret  * term(y1, p, y2, x2, p) % MOD;
	}
	
	d--; dbg("term out:");
	return ret;
}

int factor(int y1, int x1, int y2, int x2, int& p){
	dbg("factor in:"); d++;
	int line = cut(y1, x1, y2, x2), ret = -1;
	p = x1;
	
	if(x2 - x1 < 2){
		ret = powexp(y1, x1, y2, x2, p);
	}
	else if(str[line][x1] == '-' && str[line][x1+1] == '-'){
		ret = fraction(y1, x1, y2, x2, p);
	}
	else if(str[line][x1] == '-'){
		p = x1 + 2;
		ret = (MOD - factor(y1, p, y2, x2, p)) % MOD;
	}
	else{
		ret = powexp(y1, x1, y2, x2, p);
	}

	d--; dbg("factor out:");
	return ret;
}

int powexp(int y1, int x1, int y2, int x2, int& p){
	dbg("powexp in:"); d++;

	int line = cut(y1, x1, y2, x2);
	p = x1;
	int ret = primary(y1, x1, y2, x2, p);
	if(p < x2 && line-1 >= y1 && isdigit(str[line-1][p]) ){
		int dig = digit(y1, p, y2, x2, p);
		ret = pow_calc(ret, dig);
	}
	
	d--; dbg("powexp out:");
	return ret;
}

int primary(int y1, int x1, int y2, int x2, int& p){
	dbg("primary in:"); d++;

	int line = cut(y1, x1, y2, x2), ret = -1;
	p = x1;	
	if(str[line][x1] == '('){
		p += 2;
		ret = expr(y1, p, y2, x2, p);
		p += 2;
		
	}
	else{
		ret = digit(y1, x1, y2, x2, p);
	}
	
	d--;dbg("primary out:");
	return ret;
}

int fraction(int y1, int x1, int y2, int x2, int& p){
	dbg("fraction in:"); d++;
	int line = cut(y1, x1, y2, x2);
	p = x1;

	int pp = 0;
	while(p < x2 && str[line][p] == '-') p++;
	pp = x1;	
	int nume = expr(y1, x1, line, x2, pp);
	pp = x1;
	int deno = expr(line+1, x1, y2, x2, pp);
	d--; dbg("fraction out:");
	return nume * inv[deno] % MOD;
}


int digit(int y1, int x1, int y2, int x2, int& p){
	dbg("digit in:"); d++;
	int line = cut(y1, x1, y2, x2);
	p = x1;
	d--;dbg("digit out:");
	return str[line][p++]&15;
}


bool init(){
	scanf("%d ", &H);
	for(int i=0; i<H; i++){
		scanf("%s ", str[i]);
	}
	return H > 0;
}

int solve(){
	d = 0;
	int p = 0;
	W = strlen(str[0]);
	return expr(0, 0, H, W, p);
}

void pre(){
	for(int i=0; i<MOD; i++){
		inv[i] = pow_calc(i, MOD-2);
	}
}

int main(){
	pre();
	while(init()){
		printf("%d\n", solve());
	}
	return 0;
}

Measured memory_bytes: 0