#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int n, m;
vector<pair<int, short>> g[N];
int dp[N][N][26];
int dfs(int a, int b, short c) {
  if (dp[a][b][c] != -1) return dp[a][b][c];
  int ret = 0;
  for (const auto &e : g[a]) {
    if (e.second < c) continue;
    ret = ret || !dfs(b, e.first, e.second);
  }
  return dp[a][b][c] = ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (short k = 0; k < 26; ++k) {
        dp[i][j][k] = -1;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    char c;
    scanf("%d %d %c", &u, &v, &c);
    g[u].push_back(make_pair(v, c - 'a'));
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      putchar('B' - dfs(i, j, 0));
    }
    putchar('\n');
  }
  return 0;
}
