#include <bits/stdc++.h>
using namespace std;
struct node {
  int e;
  int c;
};
int n, m;
int dp[105][105][30];
vector<node> g[105];
int dfs(int u, int v, int c) {
  if (dp[u][v][c] != -1) return dp[u][v][c];
  dp[u][v][c] = 0;
  for (int i = 0; i < g[u].size(); i++) {
    if (dfs(v, g[u][i].e, g[u][i].c) == 0 && g[u][i].c >= c) {
      dp[u][v][c] = 1;
      return 1;
    }
  }
  return 0;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 1, u, v; i <= m; i++) {
    char c;
    cin >> u >> v >> c;
    c = c - 'a' + 1;
    g[u].push_back((node){v, c});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0))
        cout << "A";
      else
        cout << "B";
    }
    cout << '\n';
  }
  return 0;
}
