#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, char> > > gr;
vector<vector<array<int, 26> > > win;
vector<vector<int> > done;
void dfs(int i, int j) {
  if (done[i][j]) return;
  for (auto v : gr[i]) {
    dfs(j, v.first);
    if (!win[j][v.first][v.second])
      for (int k = 0; k <= v.second; k++) win[i][j][k] = true;
  }
  done[i][j] = true;
}
int main() {
  int n, m;
  cin >> n >> m;
  gr.resize(n);
  done.resize(n, vector<int>(n));
  win.resize(n, vector<array<int, 26> >(n));
  for (int i = 0; i < m; i++) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    gr[u - 1].push_back({v - 1, c - 'a'});
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dfs(i, j);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (win[i][j][0])
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
