#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
vector<int> val(300010, 1), vis(300010, 0), dis(300010, -1),
    mini(300010, 1000000007);
vector<pair<int, int>> adj[110];
int myrandom(int i) { return std::rand() % i; }
int dp[110][110][26];
int solve(int i, int j, int l) {
  int ret = dp[i][j][l];
  if (ret != -1) return ret;
  ret = 0;
  for (auto u : adj[i]) {
    if (l <= u.second && !solve(j, u.first, u.second)) {
      return dp[i][j][l] = 1;
    }
  }
  return dp[i][j][l] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; 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 <= n; i++) {
    for (int j = 1; j <= n; j++) {
      solve(i, j, 0) ? cout << "A" : cout << "B";
    }
    cout << '\n';
  }
}
