#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e2 + 5;
int ans[N][N][N];
bool was[N][N][N];
vector<pair<int, int> > adj[N];
bool calc(int x, int y, int pr) {
  if (was[x][y][pr]) return ans[x][y][pr];
  was[x][y][pr] = 1;
  for (auto to : adj[x]) {
    if (to.second >= pr && !calc(y, to.first, to.second)) {
      ans[x][y][pr] = 1;
      break;
    }
  }
  return ans[x][y][pr];
}
int main() {
  ios ::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    adj[u].push_back({v, c - 'a'});
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (!calc(i, j, 0))
        cout << 'B';
      else
        cout << 'A';
    }
    cout << '\n';
  }
  return 0;
}
