#include <array>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <iostream>
using namespace std;

constexpr int MAX_N = 20;
int n;
int len;
array<string, MAX_N> expression;

constexpr int mod = 2011;
int inverse[mod];

void calc_inverse() {
	inverse[1] = 1;
	for(int i = 2; i < mod; ++i) {
		inverse[i] = inverse[mod % i] * (mod - mod / i) % mod;
	}
}

int find_base(int top, int bottom, int &pos) {
	for(; pos < len; ++pos) {
		for(int i = top; i <= bottom; ++i) {
			if(expression[i][pos] != '.') {
				return i;
			}
		}
	}
	assert(false);
}

int expr(int top, int base, int bottom, int &pos);
int term(int top, int base, int bottom, int &pos);
int factor(int top, int base, int bottom, int &pos);
int powexpr(int top, int base, int bottom, int &pos);
int primary(int top, int base, int bottom, int &pos);
int fraction(int top, int base, int bottom, int &pos);

int expr(int top, int base, int bottom, int &pos) {
	int res = term(top, base, bottom, pos);
	while(pos + 3 < len && expression[base][pos] == '.'
		  && (expression[base][pos + 1] == '+'
			  || expression[base][pos + 1] == '-')) {
		assert(expression[base][pos + 2] == '.');
		const bool plus = (expression[base][pos + 1] == '+');
		pos += 3;
		if(plus) {
			res = (res + term(top, base, bottom, pos)) % mod;
		}
		else {
			res = (res - term(top, base, bottom, pos) + mod) % mod;
		}
	}
	return res;
}

int term(int top, int base, int bottom, int &pos) {
	int res = factor(top, base, bottom, pos);
	while(pos + 3 < len && expression[base][pos + 1] == '*') {
		assert(expression[base][pos++] == '.');
		assert(expression[base][pos++] == '*');
		assert(expression[base][pos++] == '.');
		res = (res * factor(top, base, bottom, pos)) % mod;
	}
	return res;
}

int factor(int top, int base, int bottom, int &pos) {
	if(pos + 2 < len && expression[base][pos] == '-') {
		if(expression[base][pos + 1] == '-') {
			return fraction(top, base, bottom, pos);
		}
		++pos;
		assert(expression[base][pos++] == '.');
		return mod - factor(top, base, bottom, pos);
	}
	return powexpr(top, base, bottom, pos);
}

int powexpr(int top, int base, int bottom, int &pos) {
	int res = primary(top, base, bottom, pos);
	if(base > 0 && isdigit(expression[base - 1][pos])) {
		const int e = expression[base - 1][pos] - '0';
		++pos;
		if(e == 0) {
			res = 1;
		}
		else {
			const int tmp = res;
			for(int i = 1; i < e; ++i) {
				res = (res * tmp) % mod;
			}
		}
	}
	return res;
}

int primary(int top, int base, int bottom, int &pos) {
	if(isdigit(expression[base][pos])) return expression[base][pos++] - '0';
	assert(expression[base][pos++] == '(');
	assert(expression[base][pos++] == '.');
	const int res = expr(top, base, bottom, pos);
	assert(expression[base][pos++] == '.');
	assert(expression[base][pos++] == ')');

	return res;
}

int fraction(int top, int base, int bottom, int &pos) {
	int pos_above = pos, pos_under = pos;
	const int base_above = find_base(top, base - 1, pos_above);
	const int base_under = find_base(base + 1, bottom, pos_under);
	while(expression[base][pos] == '-') ++pos;
	const int numerator  = expr(top, base_above, base - 1, pos_above);
	const int denominator = expr(base + 1, base_under, bottom, pos_under);
	return (numerator * inverse[denominator]) % mod;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	calc_inverse();
	while(cin >> n && n) {
		for(int i = 0; i < n; ++i) {
			cin >> expression[i];
		}

		len = expression[0].size();
		const int top = 0, bottom = n - 1;
		int pos = 0;
		const int base = find_base(top, bottom, pos);
		cout << expr(top, base, bottom, pos) << endl;
		assert(pos == len);
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1220