#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int power(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret *= a;
    a *= a;
    if (ret >= MOD) ret %= MOD;
    if (a >= MOD) a %= MOD;
    b >>= 1;
  }
  return ret;
}
int invmod(int x) { return power(x, MOD - 2); }
vector<pair<int, int> > adj[10000];
vector<int> v[10000];
int dp[105][105][30][2];
int dfs(int i, int j, int prv, bool gg) {
  if (dp[i][j][prv][gg] != -1) return dp[i][j][prv][gg];
  bool pp = false;
  int ans = -1, fans = -1;
  if (gg) {
    ans = 0;
    fans = 0;
    for (auto it : adj[i]) {
      if (it.second >= prv) {
        pp = true;
        ans = dfs(it.first, j, it.second, gg ^ 1);
        if (ans == 1) fans = 1;
      }
    }
  } else {
    ans = 1;
    fans = 1;
    for (auto it : adj[j]) {
      if (it.second >= prv) {
        pp = true;
        ans = dfs(i, it.first, it.second, gg ^ 1);
        if (ans == 0) fans = 0;
      }
    }
  }
  if (!pp) {
    if (gg)
      dp[i][j][prv][gg] = 0;
    else
      dp[i][j][prv][gg] = 1;
  } else
    dp[i][j][prv][gg] = fans;
  return dp[i][j][prv][gg];
}
int main() {
  int n, i, m, u, v, j;
  char c;
  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (i = 0; i < m; i++) {
    cin >> u >> v >> c;
    adj[u].push_back({v, c - 'a'});
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      int ans = dfs(i, j, 0, 1);
      if (ans == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
