#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
typedef string::const_iterator State;
typedef vector<int> vi;
typedef vector<vi> vv;
int n,mod=1<<15;
vv mat[26];
string s;
vv expr(State &be);
bool isvar(char c){
	return ('A'<=c && c<='Z');
}
vv inv(vv x){
	vv ret=x;
	rep(i,x.size()) rep(j,x[0].size()) ret[i][j]=-x[i][j];
	return ret;
}
vv add(vv x, vv y){
	vv ret=x;
	rep(i,x.size()) rep(j,x[0].size()) ret[i][j]+=y[i][j];
	return ret;
}
vv sub(vv x, vv y){
	vv ret=x;
	rep(i,x.size()) rep(j,x[0].size()) ret[i][j]-=y[i][j];
	return ret;
}
vv scalar(int sc,vv x){
	vv ret=x;
	rep(i,x.size()) rep(j,x[0].size()) ret[i][j]*=sc;
	return ret;
}
vv mal(vv x,vv y){
	int x1=x.size(),x2=x[0].size(),y1=y.size(),y2=y[0].size();
	if(x1==1 && x2==1){
		return scalar(x[0][0],y);
	}
	if(y1==1 && y2==1){
		return scalar(y[0][0],x);
	}
	vv ret(x1,vi(y2));
	rep(i,x1) rep(j,y2) rep(k,x2) ret[i][j]+=x[i][k]*y[k][j];
	return ret;
}
int inum(State &be){
	int ret=0;
	while(isdigit(*be)){
		ret*=10;
		ret+=(*be-'0');
		be++;
	}
	return ret;
}
vv row(State &be){
	vv ret=expr(be);
	while(*be==' '){
		be++;
		vv tmp=expr(be);
		rep(i,ret.size()) ret[i].insert(ret[i].end(),tmp[i].begin(),tmp[i].end());
	}
	return ret;
}
vv rowseq(State &be){
	vv ret=row(be);
	while(*be==';'){
		be++;
		vv tmp=row(be);
		rep(i,tmp.size()) ret.pb(tmp[i]);
	}
	return ret;
}
vv matrix(State &be){
	vv ret=rowseq(be);
	be++;
	return ret;
}
vv primary(State &be){
	vv rt;
	if(isdigit(*be)){//inum
		vv ret(1,(vi(1)));
		ret[0][0]=inum(be);
		rt=ret;
	}else if(isvar(*be)){//var
		int k=*be-'A';
		be++;
		rt=mat[k];
	}else if(*be=='['){//matrix
		be++;
		vv ret=matrix(be);
		rt=ret;
	}else if(*be=='('){
		be++;
		vv ret=expr(be);
		be++;
		rt=ret;
	}
	while(true){
		if(*be=='('){
			be++;
			vv a=expr(be);
			be++;
			vv b=expr(be);
			be++;
			int n=a[0].size(),m=b[0].size();
			vv ret(n,vi(m));
			rep(i,n) rep(j,m){
				ret[i][j]=rt[(a[0][i]%mod+mod)%mod-1][(b[0][j]%mod+mod)%mod-1];
			}
			rt=ret;
		}else if(*be=='\''){
			be++;
			int n=rt.size(),m=rt[0].size();
			vv ret(m,vi(n));
			rep(i,m) rep(j,n) ret[i][j]=rt[j][i];
			rt=ret;
		}else break;
	}
	return rt;
	//indexed
	//transposed
}
vv factor(State &be){
	if(*be=='-'){
		be++;
		return inv(factor(be));
	}else{
		return primary(be);
	}
}
vv term(State &be){
	vv ret=factor(be);
	while(true){
		if(*be=='*'){
			be++;
			ret=mal(ret,term(be));
		}else break;
	}
	return ret;
}
vv expr(State &be){
	vv ret=term(be);
	while(true){
		if(*be=='+'){
			be++;
			ret=add(ret,term(be));
		}else if(*be=='-'){
			be++;
			ret=sub(ret,term(be));
		}else{
			break;
		}
	}
	return ret;
}
void assignment(State &be){
	int k=*be-'A';
	be+=2;
	mat[k]=expr(be);
	rep(i,mat[k].size()){
		rep(j,mat[k][0].size()){
			int &x=mat[k][i][j];
			x=(x%mod+mod)%mod;
			if(j!=mat[k][0].size()-1) printf("%d ",x);
			else printf("%d\n",x);
		}
	}
}
int main(){
	while(true){
		scanf("%d",&n);
		if(n==0) break;
		scanf("\n");
		rep(i,26) mat[i].clear();
		rep(i,n){
			getline(cin,s);
			State be=s.begin();
			assignment(be);
		}
		printf("-----\n");
	}
	return 0;
}

Measured memory_bytes: 1628