#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int> > > node;
int memo[101][101][2][26];
int dfs(int p1, int p2, bool turn, int a) {
  if (memo[p1][p2][turn][a] != -1) return memo[p1][p2][turn][a];
  int ret = 0;
  if (!turn) {
    for (auto i : node[p1]) {
      if (i.second - 'a' >= a && !dfs(i.first, p2, !turn, i.second - 'a'))
        return memo[p1][p2][turn][a] = true;
    }
  } else {
    for (auto i : node[p2]) {
      if (i.second - 'a' >= a && !dfs(p1, i.first, !turn, i.second - 'a'))
        return memo[p1][p2][turn][a] = true;
    }
  }
  return memo[p1][p2][turn][a] = ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(memo, -1, sizeof memo);
  cin >> n >> m;
  node = vector<vector<pair<int, int> > >(n + 1);
  while (m--) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    node[u].push_back({v, c});
  }
  for (auto i = 1; i <= (long long)(n); i++) {
    for (auto j = 1; j <= (long long)(n); j++) {
      if (dfs(i, j, 0, 0))
        cout << "A";
      else
        cout << "B";
    }
    cout << '\n';
  }
  return 0;
}
