#include<bits/stdc++.h>

using namespace std;

typedef vector< int > vec;
typedef vector< vector< int > > mat;
const int mod = 32768;

mat expr();

void output(const mat &s)
{
  for(auto &a : s) {
    for(int j = 0; j < a.size(); j++) {
      if(j > 0) cout << " ";
      cout << a[j];
    }
    cout << endl;
  }
}

mat operator-(const mat &s)
{
  mat res(s);
  for(auto &a : res) for(auto &b : a) b = (mod - b) % mod;
  return (res);
}

mat operator+(const mat &s, const mat &t)
{
  mat res(s.size(), vec(s[0].size()));
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < s[0].size(); j++) {
      res[i][j] = (s[i][j] + t[i][j]) % mod;
    }
  }
  return (res);
}

mat operator-(mat &s, const mat &t)
{
  return s + -t;
}

mat operator*(const mat &s, const int x)
{
  mat res(s);
  for(auto &a : res) for(auto &b : a) (b *= x) %= mod;
  return (res);
}

mat operator*(const mat &s, const mat &t)
{
  if(s.size() == 1 && s[0].size() == 1) return (t * s[0][0]);
  if(t.size() == 1 && t[0].size() == 1) return (s * t[0][0]);
  mat res(s.size(), vec(t[0].size(), 0));
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < t[0].size(); j++) {
      for(int k = 0; k < t.size(); k++) {
        (res[i][j] += s[i][k] * t[k][j] % mod) %= mod;
      }
    }
  }
  return (res);
}


mat beet[256];
string s;
int idx;

mat inum()
{
  int ret = 0;
  while(isdigit(s[idx])) ret = ret * 10 + s[idx++] - '0';
  return (mat(1, vec(1, ret)));
}

mat row()
{
  mat ret = expr();
  while(s[idx] == ' ') {
    idx++;
    mat get = expr();
    for(int i = 0; i < ret.size(); i++) {
      copy(get[i].begin(), get[i].end(), back_inserter(ret[i]));
    }
  }
  return (ret);
}

mat row_seq()
{
  mat ret = row();
  while(s[idx] == ';') {
    ++idx;
    mat get = row();
    copy(get.begin(), get.end(), back_inserter(ret));
  }
  return (ret);
}

mat matrix()
{
  ++idx;
  auto ret = row_seq();
  ++idx;
  return (ret);
}

mat transposed_primary(const mat &s)
{
  ++idx;
  mat res(s[0].size(), vec(s.size()));
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < s[0].size(); j++) {
      res[j][i] = s[i][j];
    }
  }
  return (res);
}

mat indexed_primary(const mat &st)
{
  ++idx;
  mat get1 = expr();
  ++idx;
  mat get2 = expr();
  ++idx;

  mat res(get1[0].size(), vec(get2[0].size(), 0));
  for(int i = 0; i < get1[0].size(); i++) {
    for(int j = 0; j < get2[0].size(); j++) {
      res[i][j] = st[get1[0][i] - 1][get2[0][j] - 1];
    }
  }
  return (res);
}

mat primary()
{
  mat ret;
  if(isdigit(s[idx])) ret = inum();
  else if(isalpha(s[idx])) ret = beet[s[idx++]];
  else if(s[idx] == '[') ret = matrix();
  else {
    ++idx;
    ret = expr();
    ++idx;
  }

  while(s[idx] == '(' || s[idx] == '\'') {
    if(s[idx] == '(') ret = indexed_primary(ret);
    else ret = transposed_primary(ret);
  }
  return (ret);
}

mat factor()
{
  if(s[idx] == '-') {
    ++idx;
    return (-factor());
  } else {
    return (primary());
  }
}

mat term()
{
  mat ret = factor();
  while(s[idx] == '*') {
    ++idx;
    ret = ret * factor();
  }
  return (ret);
}

mat expr()
{
  mat ret = term();
  while(s[idx] == '+' || s[idx] == '-') {
    if(s[idx++] == '+') ret = ret + term();
    else ret = ret - term();
  }
  return (ret);
}


int main()
{
  int N;
  while(cin >> N, N) {
    cin.ignore();
    for(int i = 0; i < N; i++) {
      getline(cin, s);
      idx = 2;
      output(beet[s[0]] = expr());
    }
    cout << "-----" << endl;
  }
}

Measured memory_bytes: 3364