#include <bits/stdc++.h>
using namespace std;
bool func(int a, int b, int c, const vector<vector<vector<int>>>& G,
          vector<vector<vector<int>>>& arr) {
  if (arr[a][b][c] != -1) return arr[a][b][c];
  arr[a][b][c] = 0;
  for (int i = c; i < int(26); ++i)
    for (auto& x : G[i][a])
      if (!func(b, x, i, G, arr)) arr[a][b][c] = 1;
  return arr[a][b][c];
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  char temp[] = {'B', 'A'};
  vector<vector<vector<int>>> G(26, vector<vector<int>>(n));
  for (int i = 0; i < int(m); ++i) {
    int x, y;
    cin >> x >> y;
    char c;
    cin >> c;
    G[c - 'a'][x - 1].push_back(y - 1);
  }
  vector<vector<vector<int>>> arr(n,
                                  vector<vector<int>>(n, vector<int>(26, -1)));
  for (int i = 0; i < int(arr.size()); ++i) {
    for (int j = 0; j < int(arr.size()); ++j)
      cout << temp[func(i, j, 0, G, arr)];
    cout << endl;
  }
  return 0;
}
