#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char> > vec[103];
bool dp[103][103][2][300];
bool declared[103][103][2][300];
bool f(int u1, int u2, int turn, char round) {
  if (declared[u1][u2][turn][round]) return dp[u1][u2][turn][round];
  if (turn == 1) {
    for (int i = 0; i < vec[u1].size(); i++) {
      int v = vec[u1][i].first;
      char c = vec[u1][i].second;
      if (c >= round && f(v, u2, 0, c) == false) {
        declared[u1][u2][turn][round] = 1;
        return dp[u1][u2][turn][round] = 1;
      }
    }
    declared[u1][u2][turn][round] = 1;
    return dp[u1][u2][turn][round] = 0;
  } else {
    for (int i = 0; i < vec[u2].size(); i++) {
      int v = vec[u2][i].first;
      char c = vec[u2][i].second;
      if (c >= round && f(u1, v, 1, c) == false) {
        declared[u1][u2][turn][round] = 1;
        return dp[u1][u2][turn][round] = 1;
      }
    }
    declared[u1][u2][turn][round] = 1;
    return dp[u1][u2][turn][round] = 0;
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    vec[u].push_back({v, c});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (f(i, j, 1, 'a') == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << "\n";
  }
  return 0;
}
