#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, m;
vector<pair<long long, long long>> AdjList[105];
char isWin[101][101][26][2];
long long solve(long long Max, long long Lucas, long long prev,
                long long turn) {
  if (isWin[Max][Lucas][prev][turn] != -1) return isWin[Max][Lucas][prev][turn];
  long long all = 1;
  long long anyValid = 0;
  if (!turn) {
    for (auto v : AdjList[Max])
      if (v.first >= prev) {
        anyValid = 1;
        if (!solve(v.second, Lucas, v.first, !turn)) all = 0;
      }
    if (!anyValid) return isWin[Max][Lucas][prev][turn] = 0;
    if (all) return isWin[Max][Lucas][prev][turn] = 0;
    return isWin[Max][Lucas][prev][turn] = 1;
  } else {
    for (auto v : AdjList[Lucas])
      if (v.first >= prev) {
        anyValid = 1;
        if (!solve(Max, v.second, v.first, !turn)) all = 0;
      }
    if (!anyValid) return isWin[Max][Lucas][prev][turn] = 0;
    if (all) return isWin[Max][Lucas][prev][turn] = 0;
    return isWin[Max][Lucas][prev][turn] = 1;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    char w;
    cin >> u >> v >> w;
    AdjList[u].push_back({w - 'a', v});
  }
  memset(isWin, -1, sizeof(isWin));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      if (solve(i, j, 0, 0))
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
}
