#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> adj[101];
int dp[101][101][2][26];
int solve(int a, int b, int chance, char start) {
  int& res = dp[a][b][chance][start];
  if (res != -1) return res;
  if (chance) {
    res = 0;
    for (auto x : adj[a]) {
      if (x.second >= start) res |= solve(x.first, b, 1 - chance, x.second);
    }
  } else {
    res = 1;
    for (auto x : adj[b]) {
      if (x.second >= start) res &= solve(a, x.first, 1 - chance, x.second);
    }
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int v, e;
  cin >> v >> e;
  for (int i{}; i < e; ++i) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    adj[a].push_back({b, c - 'a'});
  }
  memset(dp, -1, sizeof(dp));
  for (int i{1}; i <= v; ++i) {
    for (int j{1}; j <= v; ++j) {
      cout << (solve(i, j, 1, 0) ? "A" : "B");
    }
    cout << '\n';
  }
  return 0;
}
