#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
int dp[101][101][27][2];
int dfsM(int M, int L, int c);
int dfsL(int M, int L, int c) {
  if (dp[M][L][c][0] != -1) {
    return dp[M][L][c][0];
  }
  for (auto i : g[L]) {
    int u;
    char w;
    tie(u, w) = i;
    if (w >= c && !dfsM(M, u, w)) {
      dp[M][L][c][0] = 1;
      return 1;
    }
  }
  dp[M][L][c][0] = 0;
  return 0;
}
int dfsM(int M, int L, int c) {
  if (dp[M][L][c][1] != -1) {
    return dp[M][L][c][1];
  }
  for (auto i : g[M]) {
    int u;
    char w;
    tie(u, w) = i;
    if (w >= c && !dfsL(u, L, w)) {
      dp[M][L][c][1] = 1;
      return 1;
    }
  }
  dp[M][L][c][1] = 0;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    char w;
    cin >> x >> y >> w;
    x--;
    y--;
    g[x].push_back({y, w - 'a'});
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dfsM(i, j, 0)) {
        cout << 'A';
      } else {
        cout << 'B';
      }
    }
    cout << endl;
  }
}
