#include <bits/stdc++.h>
const long long int MOD = 1000000007ll;
const int mxsz = 2e5 + 5;
using namespace std;
int n, m;
vector<pair<int, int> > adj[105];
int ans[105][105] = {};
int dp[105][105][26];
int fun(int i, int j, int c) {
  if (dp[i][j][c] != -1) {
    return dp[i][j][c];
  }
  for (int k = 0; k < adj[i].size(); k++) {
    if (adj[i][k].second >= c) {
      if (fun(j, adj[i][k].first, adj[i][k].second) == 0) {
        dp[i][j][c] = 1;
      }
    }
  }
  if (dp[i][j][c] == -1) {
    dp[i][j][c] = 0;
  }
  return dp[i][j][c];
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= m; i++) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    adj[u].push_back(make_pair(v, c - 'a'));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ans[i][j] = fun(i, j, 0);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (ans[i][j] == 1) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << endl;
  }
  return 0;
}
