#include <bits/stdc++.h>
using namespace std;
map<int, int> dp;
vector<vector<pair<int, char> > > graph;
int encode(int from1, int from2, char c) {
  return (from1) + (from2 << 7) + (int(c) << 14);
}
int calc(int state) {
  if (dp[state] != 0) return dp[state];
  int from1 = (state) % 128;
  int from2 = (state / 128) % 128;
  char c = (state / 128 / 128);
  for (int i = 0; i < graph[from1].size(); i++) {
    if (graph[from1][i].second >= c &&
        calc(encode(from2, graph[from1][i].first, graph[from1][i].second)) ==
            2) {
      dp[state] = 1;
      return 1;
    }
  }
  dp[state] = 2;
  return 2;
}
int main() {
  int n, m;
  cin >> n >> m;
  graph = vector<vector<pair<int, char> > >(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    graph[a - 1].push_back(make_pair(b - 1, c));
  }
  map<int, int> dp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (calc(encode(i, j, 'a')) == 1)
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
