#include <bits/stdc++.h>
using namespace std;
int visit[123][123][123][2], dp[123][123][123][2];
vector<vector<pair<int, int> > > adj(123);
int compute(int p, int q, int previ, int turn) {
  if (visit[p][q][previ][turn]) return dp[p][q][previ][turn];
  int val, i, haha;
  visit[p][q][previ][turn] = 1;
  if (turn == 1) {
    if (previ == adj[q].size()) {
      dp[p][q][previ][turn] = 0;
      return 0;
    }
    val = compute(p, q, previ + 1, turn);
    if (val == 1) {
      dp[p][q][previ][turn] = 1;
      return 1;
    }
    haha = lower_bound(adj[p].begin(), adj[p].end(),
                       make_pair(adj[q][previ].first, -1)) -
           adj[p].begin();
    val = compute(p, adj[q][previ].second, haha, turn ^ 1);
    dp[p][q][previ][turn] = val;
    return val;
  } else {
    dp[p][q][previ][turn] = compute(q, p, previ, turn ^ 1) ^ 1;
    return dp[p][q][previ][turn];
  }
  return 0;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int i, j;
  int u, v;
  char ch;
  for (i = 0; i < m; i++) {
    cin >> u >> v >> ch;
    u--;
    v--;
    adj[u].push_back(make_pair(ch - 'a' + 1, v));
  }
  for (i = 0; i < n; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
  int val;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      val = compute(i, j, 0, 0);
      if (val == 0) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << endl;
  }
  return 0;
}
