#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<cstdlib>
#include<iostream>

using namespace std;

#define debug(...) printf("%d:",__LINE__);printf(__VA_ARGS__)
#define debug(...) ;

#define MOD 32768

typedef vector<vector<int> > mat;
map<char,mat> varmap;

char *p;

mat expr();

void print_mat(mat m) {
    printf("/*******\n");
    for(int i=0; i<m.size(); i++)
        for(int j=0; j<m[i].size(); j++)
            printf("%d%c", m[i][j], (j==m[i].size()-1) ? '\n' : ' ');
    printf("*******/\n");
}
bool isscalar(mat src) {
    return src.size() == 1 && src[0].size() == 1;
}
mat var() {
    return varmap[*p++];
}
mat new_mat(int x,int y) {
    mat res(y);
    for(int i=0; i<y; i++) {
        res[i].resize(x);
    }
    return res;
}
int inum() {
    int res = atoi(p);
    while(isdigit(*p)) p++;
    return res % MOD;
}
mat add(mat fir, mat sec) {
    mat res = new_mat(fir[0].size(),fir.size());
    for(int y=0; y<sec.size(); y++)
        for(int x=0; x<sec[y].size(); x++)
            res[y][x] = (fir[y][x] + sec[y][x]) %MOD;
    return res;
}
mat sub(mat fir, mat sec) {
    mat res = new_mat(fir[0].size(),fir.size());
    for(int y=0; y<sec.size(); y++)
        for(int x=0; x<sec[y].size(); x++)
            res[y][x] = (fir[y][x] - sec[y][x] + MOD) %MOD;
    return res;
}
mat mul(mat fir, mat sec) {
    if(isscalar(fir)) {
        mat res = new_mat(sec[0].size(),sec.size());
        for(int y=0; y<sec.size(); y++)
            for(int x=0; x<sec[y].size(); x++)
                res[y][x] = (fir[0][0] * sec[y][x]) % MOD;
        return res;
    }
    if(isscalar(sec)) {
        mat res = new_mat(fir[0].size(),fir.size());
        for(int y=0; y<fir.size(); y++)
            for(int x=0; x<fir[y].size(); x++)
                res[y][x] = (sec[0][0] * fir[y][x]) % MOD;
        return res;
    }
    mat res = new_mat(sec[0].size(),fir.size());

    for(int y=0; y<fir.size(); y++)
        for(int x=0; x<sec[0].size(); x++) {
            res[y][x] = 0;
            for(int k=0; k<fir[y].size(); k++)
                res[y][x] += (sec[k][x] * fir[y][k]) % MOD; // Why!?
        }
    return res;

}
mat s2m (int s) { // scalar to matrix
    mat m = new_mat(1,1);
    m[0][0] = s % MOD;
    return m;
}
mat indexed(mat src, mat fir, mat sec) {
    mat res = new_mat(sec[0].size(),fir[0].size());
    for(int y=0; y<fir[0].size(); y++)
        for(int x=0; x<sec[0].size(); x++)
            res[y][x] = src[fir[0][y]-1][sec[0][x]-1];
    return res;

}
mat trans(mat m) {
    mat res = new_mat(m.size(), m[0].size());
    for(int y=0; y<m.size(); y++)
        for(int x=0; x<m[y].size(); x++)
            res[x][y] = m[y][x];
    return res;
}
mat row() {
    debug("%c\n",*p);
    mat res = expr();
    while(*p == ' ') {
        p++;
        mat r = row();
        int sx=res[0].size();
        res.resize(r.size());
        for(int m=0; m<r.size(); m++) {
            for(int n=0; n<r[m].size(); n++) {
                res[m].resize(sx+n+1);
                res[m][sx+n] = r[m][n];
            }
        }
    }

    return res;
}
mat row_seq() {
    debug("%c\n",*p);
    mat res = row();
    while(*p == ';') {
        p++;
        mat r = row();
        for(int y=0; y<r.size(); y++)
            res.push_back(r[y]);
    }
    return res;
}
mat matrix() {
    debug("%c\n",*p);
    p++;
    mat res = row_seq();
    p++;
    return res;
}
mat primary() {
    debug("%c\n",*p);
    mat res;
    if(isdigit(*p)) res = s2m(inum());
    else if(isalpha(*p)) res = var();
    else if(*p == '[') res = matrix();
    else if(*p == '(') p++, res = expr(), p++;

    while(*p == '\'' || *p == '(') {
        while(*p == '\'') res = trans(res), p++;
        while(*p == '(') {
            p++;
            mat fir,sec;
            fir = expr();
            p++;
            sec = expr();
            p++;
            return indexed(res, fir, sec);
        }
    }

    return res;
}
mat factor() {
    debug("%c\n",*p);
    if(*p == '-') {
        p++;
        return mul(s2m(-1), factor());
    }
    return primary();
}
mat term() {
    debug("%c\n",*p);
    mat f = factor();
    if(*p == '*') {
        p++;
        mat res = mul(f,term());
        return res;
    }
    return f;
}
mat expr() {
    debug("%c\n",*p);
    mat res = term();
    while(*p == '+' || *p == '-') {
        if(*p == '+') {
            p++;
            res = add(res, term());
        }
        else if(*p == '-') {
            p++;
            res = sub(res, term());
        }
    }

    return res;
}




int main(void) {
    while(true) {
        int n;
        scanf("%d\n",&n);
        if(!n) break;

        for(int i=0; i<n; i++) {
            char in[1000];
            cin.getline(in,1000);
            p = in+2;
            mat res = expr();
            varmap[*in] = res;
            for(int y=0; y<res.size(); y++)
                for(int x=0; x<res[y].size(); x++)
                    printf("%d%c",(res[y][x] + 100*MOD)%MOD, (x+1==res[y].size()) ? '\n' : ' ');
        }
        printf("-----\n");
        varmap.clear();
    }
    return 0;
}

Measured memory_bytes: 1620