#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
const int lim = 103;
int dp[101][101][26];
vector<pair<int, int>> adj[lim];
void edgeInput(int m) {
  for (int i = 1; i <= m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    adj[a].push_back({b, (int)(c - 'a')});
  }
}
int fun(int p1, int p2, int ch) {
  if (dp[p1][p2][ch] != -1) return dp[p1][p2][ch];
  dp[p1][p2][ch] = 1;
  for (auto u : adj[p1]) {
    int node = u.first, chr = u.second;
    if (chr >= ch && fun(p2, node, chr) == 1) {
      dp[p1][p2][ch] = 0;
      break;
    }
  }
  return dp[p1][p2][ch];
}
void pre_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(dp, -1, sizeof(dp));
}
int32_t main() {
  pre_io();
  int n, m;
  cin >> n >> m;
  edgeInput(m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << (fun(i, j, 0) == 0 ? 'A' : 'B');
    }
    cout << "\n";
  }
}
