#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<char>>> dp[2];
vector<vector<pair<int, int>>> graph;
bool wins(int i, int j, int minval, bool maxgoes) {
  char& memo = dp[maxgoes][i][j][minval];
  if (memo >= 0) return memo;
  bool haswin = false;
  if (maxgoes) {
    for (auto p : graph[i]) {
      if (p.second < minval) continue;
      if (!wins(p.first, j, p.second, !maxgoes)) {
        haswin = true;
        break;
      }
    }
  } else {
    for (auto p : graph[j]) {
      if (p.second < minval) continue;
      if (!wins(i, p.first, p.second, !maxgoes)) {
        haswin = true;
        break;
      }
    }
  }
  memo = haswin;
  return haswin;
}
int main() {
  ios::sync_with_stdio(false);
  cout.precision(12);
  int n, m;
  cin >> n >> m;
  ++n;
  graph.resize(n);
  for (int k = 0; k < m; ++k) {
    int i, j;
    char c;
    cin >> i >> j >> c;
    graph[i].push_back({j, int(c - 'a')});
  }
  for (int i = 0; i < 2; ++i)
    dp[i].assign(n, vector<vector<char>>(n, vector<char>(26, char(-1))));
  for (int i = 1; i < n; ++i) {
    string s;
    for (int j = 1; j < n; ++j) s += wins(i, j, 0, true) ? 'A' : 'B';
    cout << s << endl;
  }
}
