#include <bits/stdc++.h>
using namespace std;
int dp[101][101][26][2];
vector<pair<int, char> > adj[101];
bool first(int i, int j, int ch, int p) {
  if (dp[i][j][ch][p] != 0) {
    if (dp[i][j][ch][p] == -1)
      return false;
    else
      return true;
  }
  if (p == 0) {
    bool ret = false;
    for (int t = 0; t < (int((adj[i]).size())); ++t) {
      int to = adj[i][t].first;
      int cho = adj[i][t].second - 'a';
      if (cho >= ch) {
        if (i == 2 && j == 1 && p == 0) {
        }
        ret |= first(to, j, cho, 1 - p);
      }
    }
    if (ret)
      dp[i][j][ch][p] = 1;
    else
      dp[i][j][ch][p] = -1;
    return ret;
  } else {
    bool ret = true;
    for (int t = 0; t < (int((adj[j]).size())); ++t) {
      int to = adj[j][t].first;
      int cho = adj[j][t].second - 'a';
      if (cho >= ch) {
        ret &= first(i, to, cho, 1 - p);
      }
    }
    if (ret)
      dp[i][j][ch][p] = 1;
    else
      dp[i][j][ch][p] = -1;
    return ret;
  }
}
bool ans[101][101];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    int v, u;
    char c;
    cin >> v >> u >> c;
    v--;
    u--;
    adj[v].push_back(make_pair(u, c));
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (n); ++j) {
      ans[i][j] = first(i, j, 0, 0);
    }
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (n); ++j) {
      if (ans[i][j])
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
}
