#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, char>>> g;
int m[110][110][30][2];
int solve(int f, int s, char pr, bool turn) {
  if (pr != '0' && m[f][s][pr - 'a'][turn] != -1)
    return m[f][s][pr - 'a'][turn];
  if (turn) {
    for (pair<int, char> x : g[f]) {
      if (x.second >= pr) {
        if (solve(x.first, s, x.second, false) == false) {
          if (pr == '0') return true;
          return m[f][s][pr - 'a'][turn] = true;
        }
      }
    }
    if (pr == '0') return false;
    return m[f][s][pr - 'a'][turn] = false;
  } else {
    for (pair<int, char> x : g[s]) {
      if (x.second >= pr) {
        if (solve(f, x.first, x.second, true) == false)
          return m[f][s][pr - 'a'][turn] = true;
      }
    }
    return m[f][s][pr - 'a'][turn] = false;
  }
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  g.assign(N + 1, vector<pair<int, char>>());
  int A, B;
  char c;
  memset(m, -1, sizeof(m));
  for (int m = 0; m < M; m++) {
    cin >> A >> B >> c;
    g[A].push_back({B, c});
  }
  for (int x = 1; x <= N; x++) {
    for (int y = 1; y <= N; y++) {
      if (solve(x, y, '0', true))
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
