#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int win[maxn][maxn][26];
int vis[maxn][maxn][26];
vector<pair<char, int> > adjlist[maxn];
void dfs(int first, int second, int val) {
  vis[first][second][val] = 1;
  for (auto u : adjlist[first]) {
    if (vis[second][u.second][u.first - 'a'] == 0) {
      dfs(second, u.second, u.first - 'a');
    }
    if ((u.first - 'a') >= val && win[second][u.second][u.first - 'a'] == 0)
      win[first][second][val] = 1;
  }
}
int n, m;
int u, v;
char c;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> c;
    adjlist[u].push_back({c, v});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (vis[i][j][0] == 0) dfs(i, j, 0);
      if (win[i][j][0] == 1)
        cout << 'A';
      else
        cout << 'B';
    }
    cout << '\n';
  }
  return 0;
}
