#include<cassert>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 105, MOD = 32768;

inline int norm(int n) {
	n = n % MOD;
	if (n < 0) {
		n += MOD;
	}
	return n;
}

struct Matrix {
	int n, m, a[N][N];

	const int* operator [] (const int &i) const {
		return a[i];
	}

	int* operator [] (const int i) {
		return a[i];
	}

	Matrix operator + (const Matrix &b) const {
		assert(n == b.n && m == b.m);
		Matrix c;
		c.n = n, c.m = m;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				c[i][j] = a[i][j] + b[i][j];
			}
		}
		return c;
	}

	Matrix operator - (const Matrix &b) const {
		assert(n == b.n && m == b.m);
		Matrix c;
		c.n = n, c.m = m;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				c[i][j] = a[i][j] - b[i][j];
			}
		}
		return c;
	}

	Matrix operator * (const Matrix &b) const {
		Matrix c;
		if (n == 1 && m == 1) {
			c.n = b.n, c.m = b.m;
			for (int i = 0; i < b.n; ++i) {
				for (int j = 0; j < b.m; ++j) {
					c[i][j] = a[0][0] * b[i][j];
				}
			}
		} else if (b.n == 1 && b.m == 1) {
			c.n = n, c.m = m;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					c[i][j] = a[i][j] * b[0][0];
				}
			}
		} else {
			assert(m == b.n);
			c.n = n, c.m = b.m;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < b.m; ++j) {
					c[i][j] = 0;
					for (int k = 0; k < m; ++k) {
						c[i][j] += a[i][k] * b[k][j];
					}
				}
			}
		}
		return c;
	}

	Matrix operator - () const {
		Matrix c;
		c.n = n, c.m = m;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				c[i][j] = -a[i][j];
			}
		}
		return c;
	}

	Matrix transpose() const {
		Matrix c;
		c.n = m, c.m = n;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				c[j][i] = a[i][j];
			}
		}
		return c;
	}

	Matrix index(const Matrix &r, const Matrix &c) const {
		Matrix ret;
		assert(r.n == 1 && c.n == 1);
		ret.n = r.m, ret.m = c.m;
		for (int i = 0; i < ret.n; ++i) {
			for (int j = 0; j < ret.m; ++j) {
				ret[i][j] = a[norm(r[0][i] - 1)][norm(c[0][j] - 1)];
			}
		}
		return ret;
	}

	Matrix addRow(const Matrix &b) const {
		Matrix c;
		assert(m == b.m);
		c.n = n + b.n, c.m = m;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				c[i][j] = a[i][j];
			}
		}
		for (int i = 0; i < b.n; ++i) {
			for (int j = 0; j < m; ++j) {
				c[n + i][j] = b[i][j];
			}
		}
		return c;
	}

	Matrix addCol(const Matrix &b) const {
		Matrix c;
		assert(n == b.n);
		c.n = n, c.m = m + b.m;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				c[i][j] = a[i][j];
			}
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < b.m; ++j) {
				c[i][m + j] = b[i][j];
			}
		}
		return c;
	}

	void print() const {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				printf("%d%c", norm(a[i][j]), j == m - 1 ? '\n' : ' ');
			}
		}
	}
};

const int L = 85;

int n;

char buf[L];

Matrix vars[26];

Matrix expr(char *&buf);

Matrix inum(char *&buf) {
	Matrix ret;
	ret.n = ret.m = 1;
	int &tmp = ret[0][0];
	tmp = 0;
	while (*buf >= '0' && *buf <= '9') {
		tmp = tmp * 10 + (*buf - '0');
		++buf;
	}
	return ret;
}

Matrix var(char *&buf) {
	int id = *buf - 'A';
	assert(0 <= id && id < 26);
	++buf;
	return vars[id];
}

Matrix row(char *&buf) {
	Matrix ret = expr(buf);
	while (*buf == ' ') {
		++buf;
		Matrix b = expr(buf);
		ret = ret.addCol(b);
	}
	return ret;
}

Matrix row_seq(char *&buf) {
	Matrix ret = row(buf);
	while (*buf == ';') {
		++buf;
		Matrix b = row(buf);
		ret = ret.addRow(b);
	}
	return ret;
}

Matrix matrix(char *&buf) {
	assert(*buf == '[');
	++buf;
	Matrix ret = row_seq(buf);
	assert(*buf == ']');
	++buf;
	return ret;
}

Matrix primary(char *&buf) {
	char ch = *buf;
	Matrix ret;
	if (ch >= '0' && ch <= '9') {
		ret = inum(buf);
	} else if (ch >= 'A' && ch <= 'Z') {
		ret = var(buf);
	} else if (ch == '[') {
		ret = matrix(buf);
	} else if (ch == '(') {
		ret = expr(++buf);
		assert(*buf == ')');
		++buf;
	} else {
		assert(false);
	}
	while (*buf == '(' || *buf == '\'') {
		if (*buf == '(') {
			++buf;
			Matrix r = expr(buf);
			assert(*buf == ',');
			++buf;
			Matrix c = expr(buf);
			assert(*buf == ')');
			++buf;
			ret = ret.index(r, c);
		} else if (*buf == '\'') {
			ret = ret.transpose();
			++buf;
		}
	}
	return ret;
}

Matrix factor(char *&buf) {	
	if (*buf == '-') {
		return -factor(++buf);
	} else {
		return primary(buf);
	}
}

Matrix term(char *&buf) {
	Matrix ret = factor(buf);
	while (*buf == '*') {
		Matrix b = factor(++buf);
		ret = ret * b;
	}
	return ret;
}

Matrix expr(char *&buf) {
	Matrix ret = term(buf);
	while (*buf == '+' || *buf == '-') {
		char op = *buf;
		Matrix b = term(++buf);
		if (op == '+') {
			ret = ret + b;
		} else {
			ret = ret - b;
		}
	}
	return ret;
}

Matrix assignment(char *&buf) {
	int id = *buf - 'A';
	assert(0 <= id && id < 26);
	assert(*(++buf)  == '=');
	vars[id] = expr(++buf);
	assert(*buf == '.');
	return vars[id];
}

int main() {
	while (scanf("%d", &n) == 1 && n) {
		gets(buf);
		for (int i = 0; i < n; ++i) {
			gets(buf);
			char *head = buf;
			Matrix ret = assignment(head);
			ret.print();
		}
		printf("-----\n");
	}
	return 0;
}

Measured memory_bytes: 3460