#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"



const int mod = 2011;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}
vector<string>sts;
int a;

Mod getexpr(const int top, const int bot, const int base, const int left);
Mod getprim(const int top, const int bot, const int base, const int left) {
	if (sts[base][left] == '(') {
		a += 2;
		Mod exp = getexpr(top, bot, base, left + 2);
		assert(sts[base][a] == ')');
		a += 2;
		return exp;
	}
	else {
		Mod dig = sts[base][left]-'0';
		a += 2;
		return dig;
	}
}
pair<int, int>getlb(const int top, const int bot, const int left) {
	for (int x = left; x < sts[0].size(); ++x) {
		bool flag = false;
		for (int y = top; y <=bot; ++y) {
			if (sts[y][x] != '.') {
				return make_pair(x, y);
			}
		}
	}
}
Mod getfrac(const int top, const int bot, const int base, const int left) {
	Mod bo, si;
	{
		auto p = getlb(top, base - 1, left);
		int l = p.first;
		int b = p.second;
		a = l;
		si = getexpr(top, base - 1, b, l);
	}
	{
		auto p = getlb(base+1, bot, left);
		int l = p.first;
		int b = p.second;
		a = l;
		bo = getexpr(base+1,bot, b, l);
	}
	while (sts[base][a] == '-')a++;
	a++;
	return si / bo;
}
Mod getpowx(const int top, const int bot, const int base, const int left) {
	Mod prim(getprim(top, bot, base, left));
	if (top != base&&isdigit(sts[base-1][a-1])) {
		prim = mod_pow(prim, sts[base - 1][a - 1] - '0');
		a++;
	}
	return prim;
}
Mod getfact(const int top, const int bot, const int base,const int left) {
	if (sts[base][left] == '-'&&sts[base][left + 1] == '-') {
		return getfrac(top, bot, base, left);
	}
	else if (sts[base][left] == '-') {
		a += 2;
		Mod fact = getfact(top, bot, base, a);
		return -fact;
	}
	else {
		return getpowx(top, bot, base, left);
	}
}
Mod getterm(const  int top, const  int bot,  int base, int left) {
	
	Mod fact = getfact(top, bot, base,left);
	while (a < sts[base].size()) {
		char ch(sts[base][a]);
		if (ch == ')'||ch=='.')break;
		else if (ch == '+'||ch=='-') {
			break;
		}
		else if (ch == '*') {
			a += 2;
			Mod next_fact = getfact(top, bot, base, a);
			fact *= next_fact;

		}
		else {
			assert(false);
		}
	}
	return fact;
}
Mod getexpr(const int top, const int bot, const int base,const int left) {
	Mod term = getterm(top, bot, base,left);
	while (a <  sts[base].size()) {
		char ch(sts[base][a]);
		if (ch == ')' || ch == '.')break;
		else if (ch == '+') {
			a += 2;
			Mod next_term = getterm(top, bot, base, a);
			term += next_term;
		}
		else if (ch == '-') {
			a += 2;
			Mod next_term = getterm(top, bot, base, a);
			term -= next_term;
		}
		else {
			assert(false);
		}
	}
	return term;
}

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		sts.clear();
		sts.resize(N);
		string st;
		getline(cin, st);
		for (int i = 0; i < N; ++i) {
			getline(cin, sts[i]);
		}
		auto p = getlb(0, N-1, 0);
		int l = p.first;
		int b = p.second;
		a = l;
		Mod ans = getexpr(0, N - 1, b, l);
		cout << ans << endl;
	}
	return 0;
}