#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 105;
int memo[N][N][26], n, m;
vector<pair<int, int> > adj[N];
bool rec(int v, int u, int c) {
  if (memo[v][u][c] > -1) return memo[v][u][c] == 1;
  bool temp = 1;
  for (auto p : adj[v]) {
    if (!temp) break;
    if (p.second >= c) temp = rec(u, p.first, p.second);
  }
  memo[v][u][c] = !temp;
  return memo[v][u][c] == 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    char c;
    cin >> v >> u >> c;
    adj[v].emplace_back(make_pair(u, (int)c - 'a'));
  }
  memset(memo, -1, sizeof(memo));
  string ans[N];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (rec(i, j, 0))
        ans[i] += 'A';
      else
        ans[i] += 'B';
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << endl;
  return 0;
}
