#include <bits/stdc++.h>
bool viz[109], d[109][109][27];
std::vector<int> g[109][26];
int v[109], k;
void dfs(int x) {
  viz[x] = 1;
  for (int i = 0; i < 26; i++)
    for (auto &y : g[x][i])
      if (viz[y] == 0) dfs(y);
  v[++k] = x;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    char ch;
    scanf("%d%d %c", &x, &y, &ch);
    g[x][ch - 'a'].push_back(y);
  }
  for (int i = 1; i <= n; i++)
    if (viz[i] == 0) dfs(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      for (int p = 25; p >= 0; p--) {
        d[v[i]][v[j]][p] = d[v[i]][v[j]][p + 1];
        if (d[v[i]][v[j]][p] == 0) {
          for (auto &x : g[v[i]][p])
            if (d[v[j]][x][p] == 0) d[v[i]][v[j]][p] = 1;
        }
      }
    }
    for (int j = 1; j < i; j++) {
      for (int p = 25; p >= 0; p--) {
        d[v[j]][v[i]][p] = d[v[j]][v[i]][p + 1];
        if (d[v[j]][v[i]][p] == 0) {
          for (auto &x : g[v[j]][p])
            if (d[v[i]][x][p] == 0) d[v[j]][v[i]][p] = 1;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) fputc('B' - d[i][j][0], stdout);
    fputc('\n', stdout);
  }
  return 0;
}
