#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
vector<int> val(300010, 1), vis(300010, 0), dis(300010, -1),
    mini(300010, 1000000007);
vector<pair<int, int>> adj[110];
int myrandom(int i) { return std::rand() % i; }
vector<int> v;
void dfs(int a) {
  vis[a] = 1;
  for (auto i : adj[a]) {
    if (!vis[i.first]) dfs(i.first);
  }
  v.push_back(a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    adj[a].push_back({b, c - 'a'});
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  int dp[n + 1][n + 1][26];
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k < 26; k++) {
        bool ok = false;
        for (auto l : adj[v[i]]) {
          if (k <= l.second && dp[v[j]][l.first][l.second] == 0) {
            ok = true;
          }
        }
        dp[v[i]][v[j]][k] = ok;
      }
      swap(i, j);
      for (int k = 0; k < 26; k++) {
        bool ok = false;
        for (auto l : adj[v[i]]) {
          if (k <= l.second && dp[v[j]][l.first][l.second] == 0) {
            ok = true;
          }
        }
        dp[v[i]][v[j]][k] = ok;
      }
      swap(i, j);
    }
  }
  for (int i = 1; i <= n; i++, cout << '\n') {
    for (int j = 1; j <= n; j++) {
      if (dp[i][j][0] == 1)
        cout << "A";
      else
        cout << "B";
    }
  }
}
