#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef vector<int> Array;
typedef vector<Array> Matrix;

const ll MOD = 32768;

void PrintMatrix(Matrix lhs) {
  REP(y, lhs.size()) {
    REP(x, lhs[0].size()) {
      if (x != 0) { putchar(' '); }
      printf("%d", lhs[y][x]);
    }
    puts("");
  }
}

Matrix Minus(Matrix lhs) {
  Matrix ret = lhs;
  REP(y, lhs.size()) {
    REP(x, lhs.size()) {
      ret[y][x] = (MOD - lhs[y][x]) % MOD;
    }
  }
  return ret;
}

Matrix Add(Matrix lhs, Matrix rhs) {
  Matrix ret = lhs;
  REP(y, lhs.size()) {
    REP(x, lhs[0].size()) {
      ret[y][x] = (lhs[y][x] + rhs[y][x]) % MOD;
    }
  }
  return ret;
}

Matrix Sub(Matrix lhs, Matrix rhs) {
  return Add(lhs, Minus(rhs));
}

Matrix Mul(Matrix lhs, Matrix rhs) {
  Matrix ret(lhs.size(), Array(rhs[0].size(), 0));
  if (lhs.size() == 1 && lhs[0].size() == 1) { swap(lhs, rhs); }
  if (rhs.size() == 1 && rhs[0].size() == 1) {
    ret = lhs;
    REP(y, lhs.size()) {
      REP(x, lhs[0].size()) {
        ret[y][x] = (ret[y][x] * rhs[0][0]) % MOD;
      }
    }
  } else {
    assert(lhs[0].size() == rhs.size());
    REP(y, lhs.size()) {
      REP(x, rhs[0].size()) {
        REP(k, lhs[0].size()) {
          ret[y][x] = (ret[y][x] + lhs[y][k] * rhs[k][x]) % MOD;
        }
      }
    }
  }
  return ret;
}

Matrix AppendHorizontal(Matrix lhs, Matrix rhs) {
  assert(lhs.size() == rhs.size());
  Matrix ret(lhs.size(), Array(lhs[0].size() + rhs[0].size(), 0));
  REP(y, lhs.size()) {
    REP(x, lhs[0].size()) {
      ret[y][x] = lhs[y][x];
    }
    REP(x, rhs[0].size()) {
      ret[y][lhs[0].size() + x] = rhs[y][x];
    }
  }
  return ret;
}

Matrix AppendVertical(Matrix lhs, Matrix rhs) {
  assert(lhs[0].size() == rhs[0].size());
  Matrix ret(lhs.size() + rhs.size(), Array(lhs[0].size(), 0));
  REP(x, lhs[0].size()) {
    REP(y, lhs.size()) {
      ret[y][x] = lhs[y][x];
    }
    REP(y, rhs.size()) {
      ret[lhs.size() + y][x] = rhs[y][x];
    }
  }
  return ret;
}

Matrix SubMatrix(Matrix base, Matrix ys, Matrix xs) {
  assert(ys.size() == 1 && xs.size() == 1);
  Matrix ret(ys[0].size(), Array(xs[0].size(), 0));
  REP(i, ys[0].size()) {
    REP(j, xs[0].size()) {
      ret[i][j] = base[ys[0][i] - 1][xs[0][j] - 1];
    }
  }
  return ret;
}

Matrix Transpose(Matrix lhs) {
  Matrix ret(lhs[0].size(), Array(lhs.size(), 0));
  REP(y, lhs.size()) {
    REP(x, lhs[0].size()) {
      ret[x][y] = lhs[y][x];
    }
  }
  return ret;
}

//===================================
Matrix assignment[100];
char str[10000];
int pos;
Matrix expr();

Matrix digits() {
  int v = atoi(str + pos);
  while (isdigit(str[pos])) { pos++; }
  return Matrix(1, Array(1, v));
}

Matrix row() {
  Matrix lhs = expr();
  while (str[pos] == ' ') {
    pos++;
    Matrix rhs = expr();
    lhs = AppendHorizontal(lhs, rhs);
  }
  return lhs;
}

Matrix rowseq() {
  Matrix lhs = row();
  while (str[pos] == ';') {
    pos++;
    Matrix rhs = row();
    lhs = AppendVertical(lhs, rhs);
  }
  return lhs;
}

Matrix matrix() {
  assert(str[pos] == '[');
  pos++;
  Matrix lhs = rowseq();
  assert(str[pos] == ']');
  pos++;
  return lhs;
}

Matrix primary() {
  Matrix lhs;
  if (isdigit(str[pos])) {
    lhs = digits();
  } else if (isalpha(str[pos])) {
    lhs = assignment[(int)str[pos]];
    pos++;
  } else if (str[pos] == '(') {
    pos++;
    lhs = expr();
    assert(str[pos] == ')');
    pos++;
  } else if (str[pos] == '[') {
    lhs = matrix();
  } else {
    assert(false);
  }

  while (str[pos] == '(' || str[pos] == '\'') {
    if (str[pos] == '\'') {
      pos++;
      lhs = Transpose(lhs);
    } else {
      pos++;
      Matrix ys = expr();
      assert(str[pos] == ',');
      pos++;
      Matrix xs = expr();
      assert(str[pos] == ')');
      pos++;
      lhs = SubMatrix(lhs, ys, xs);
    }
  }
  return lhs;
}

Matrix factor() {
  if (str[pos] == '-') {
    pos++;
    return Minus(factor());
  }
  return primary();
}

Matrix term() {
  Matrix lhs = factor();
  while (str[pos] == '*') {
    pos++;
    Matrix rhs = factor();
    lhs = Mul(lhs, rhs);
  }
  return lhs;
}

Matrix expr() {
  Matrix lhs = term();
  while (str[pos] == '+' || str[pos] == '-') {
    char c = str[pos];
    pos++;
    Matrix rhs = term();
    if (c == '+') { lhs = Add(lhs, rhs); }
    else if (c == '-') { lhs = Sub(lhs, rhs); }
  }
  return lhs;
}

int main() {
  int n;
  while (scanf("%d ", &n), n) {
    REP(i, 100) { assignment[i].clear(); }
    REP(i, n) {
      fgets(str, 9999, stdin);
      int c = str[0];
      assert(str[1] == '=');
      pos = 2;
      assignment[c] = expr();
      assert(str[pos] == '.');
      PrintMatrix(assignment[c]);
    }
    puts("-----");
  }
}

Measured memory_bytes: 1248