#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int dp[27][N][N][2];
vector<vector<pair<int, char>>> g;
vector<int> ord;
bool vis[N];
void toposort(int i) {
  if (vis[i]) return;
  vis[i] = true;
  for (auto& adj : g[i]) {
    toposort(adj.first);
  }
  ord.push_back(i);
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    char c;
    int u, v;
    cin >> u >> v >> c;
    --u, --v;
    g[u].emplace_back(v, c);
  }
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      toposort(i);
    }
  }
  vector<int> inv(n);
  for (int i = 0; i < n; ++i) inv[ord[i]] = i;
  for (int c = 26; c >= 0; --c) {
    for (int ii = 0; ii < n; ++ii) {
      for (int jj = 0; jj < n; ++jj) {
        dp[c][ii][jj][0] = 1;
        dp[c][ii][jj][1] = 1;
        for (auto& adj : g[ord[ii]]) {
          if (adj.second - 'a' >= c) {
            dp[c][ii][jj][0] &= dp[adj.second - 'a'][inv[adj.first]][jj][1];
          }
        }
        for (auto& adj : g[ord[jj]]) {
          if (adj.second - 'a' >= c) {
            dp[c][ii][jj][1] &= dp[adj.second - 'a'][ii][inv[adj.first]][0];
          }
        }
        dp[c][ii][jj][0] ^= 1;
        dp[c][ii][jj][1] ^= 1;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cout << (dp[0][inv[i]][inv[j]][0] ? 'A' : 'B');
    cout << '\n';
  }
  return 0;
}
