#include <bits/stdc++.h>
using namespace std;
int memo[77][107][107];
inline int index(char ch) { return (ch == '@') ? 0 : ch - 'a'; }
bool eval(char ch, int i, int j, vector<vector<pair<int, char>>> &adj) {
  int val = memo[index(ch)][i][j];
  if (val == 1) return true;
  if (val == 2) return false;
  for (auto nxt : adj[i]) {
    if (ch <= nxt.second) {
      if (!eval(nxt.second, j, nxt.first, adj)) {
        memo[index(ch)][i][j] = 1;
        return true;
      }
    }
  }
  memo[index(ch)][i][j] = 2;
  return false;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, char>>> adj(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    adj[u].push_back({v, c});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cout << (eval('@', i, j, adj) ? 'A' : 'B');
    cout << "\n";
  }
  return 0;
}
