#include <bits/stdc++.h>
using namespace std;
const int N = 102, M = 102 * 102;
int n, m;
vector<pair<int, int> > g[N];
char ans[N][N];
char dp[N][N][28] = {0};
void input() {
  cin >> n >> m;
  for (int i = (0); i < (m); ++i) {
    int u, v;
    char ch;
    cin >> u >> v >> ch;
    u--, v--;
    g[u].push_back(make_pair(v, ch - 'a'));
  }
}
int dfs(int u, int v, char c) {
  if (dp[u][v][c] != 0) return dp[u][v][c];
  for (auto x : g[u]) {
    int h = x.first;
    char k = x.second;
    int win = 0;
    if (k >= c) {
      win = dfs(v, h, k);
      if (win == 2) {
        dp[u][v][c] = 1;
        return 1;
      }
    }
  }
  dp[u][v][c] = 2;
  return 2;
}
void solve() {
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      ans[i][j] = ((dfs(i, j, 0) == 1) ? 'A' : 'B');
    }
  }
}
void output() {
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      cout << ans[i][j];
    }
    cout << "\n";
  }
}
int main() {
  input();
  solve();
  output();
}
