// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 32768LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

typedef vector<vi> mat;

int n,cur;
string s;
mat v[130];

mat expr();
mat term();
mat factor();
mat primary();
mat inum();
mat rowSeq();
mat row();

void print(mat m){
	cout<<"[";
	rep(i,sz(m))rep(j,sz(m[i])){
		cout<<m[i][j]<<(j==sz(m[i])-1 ? ";" : " ");
	}
	cout<<"]"<<endl;
}

void assign(){
	char c = s[cur];
	cur++;
	assert(s[cur]=='=');
	cur++;
	v[c] = expr();
	rep(i,sz(v[c]))rep(j,sz(v[c][i])){
		cout<<v[c][i][j];
		if(j==sz(v[c][i])-1)cout<<endl;
		else cout<<" ";
	}
}

mat expr(){
	mat m = term();
	while(s[cur] == '+' || s[cur] == '-'){
		char op = s[cur];
		cur++;
		mat m2 = term();
		rep(i,sz(m))rep(j,sz(m[i])){
			m[i][j] = (m[i][j] + m2[i][j] * (op=='+' ? +1 : -1) + MOD) % MOD;
		}
	}
	return m;
}

mat term(){
	mat m = factor();
	while(s[cur] == '*'){
		cur++;
		mat m2 = factor();
		if(sz(m)==1 && sz(m[0])==1){
			rep(i,sz(m2))rep(j,sz(m2[i])){
				m2[i][j] = (m2[i][j] * m[0][0]) % MOD;
			}
			m = m2;
		}
		else if(sz(m2)==1 && sz(m2[0])==1){
			rep(i,sz(m))rep(j,sz(m[i])){
				m[i][j] = (m[i][j] * m2[0][0]) % MOD;
			}
		}
		else{
			mat m3(sz(m),vi(sz(m2[0])));
			rep(i,sz(m))rep(j,sz(m2[0]))rep(k,sz(m[0])){
				m3[i][j] = (m3[i][j] + m[i][k] * m2[k][j]) % MOD;
			}
			m = m3;
		}
	}
	return m;
}

mat factor(){
	int minus = 0;
	while(s[cur]=='-'){
		cur++;
		minus++;
	}
	mat m = primary();
	if(minus%2==1){
		rep(i,sz(m))rep(j,sz(m[i])){
			m[i][j] = (MOD - m[i][j]) % MOD;
		}
	}
	return m;
}

mat primary(){
	mat m;
	if(isdigit(s[cur])){
		m = inum();
	}
	else if(isupper(s[cur])){
		m = v[s[cur]];
		cur++;
	}
	else if(s[cur]=='['){
		cur++;
		m = rowSeq();
		assert(']');
		cur++;
	}
	else if(s[cur]=='('){
		cur++;
		m = expr();
		assert(s[cur]==')');
		cur++;
	}
	
	while(s[cur] == '(' || s[cur] == '\''){
		if(s[cur] == '('){
			cur++;
			mat m2 = expr();
			assert(s[cur]==',');
			cur++;
			mat m3 = expr();
			assert(s[cur]==')');
			cur++;
			mat m4(sz(m2[0]),vi(sz(m3[0])));
			rep(i,sz(m2[0]))rep(j,sz(m3[0])){
				m4[i][j] = m[m2[0][i]-1][m3[0][j]-1];
			}
			m = m4;
		}
		else if(s[cur]=='\''){
			mat m2(sz(m[0]),vi(sz(m)));
			rep(i,sz(m))rep(j,sz(m[0])){
				m2[j][i] = m[i][j];
			}
			m = m2;
			cur++;
		}
	}
	return m;
}

mat inum(){
	mat m(1,vi(1));
	while(isdigit(s[cur])){
		m[0][0] = (m[0][0]*10 + s[cur]-'0') % MOD;
		cur++;
	}
	return m;
}

mat rowSeq(){
	mat m = row();
	while(s[cur] == ';'){
		cur++;
		mat m2 = row();
		rep(i,sz(m2)){
			m.pb(m2[i]);
		}
	}
	return m;
}

mat row(){
	mat m = expr();
	while(s[cur] == ' '){
		cur++;
		mat m2 = expr();
		rep(i,sz(m2))rep(j,sz(m2[i])){
			m[i].pb(m2[i][j]);
		}
	}
	return m;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n && n){
		getline(cin,s);
		rep(i,130)v[i].clear();
		rep(i,n){
			getline(cin,s);
			cur=0;
			assign();
		}
		cout<<"-----"<<endl;
	}
}

Measured memory_bytes: 1684