#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char>> G[200];
int dp[200][200][256];
int zml(int a, int b, int c) {
  if (dp[a][b][c] != -1) return dp[a][b][c];
  int flag = 0;
  for (auto o : G[a]) {
    if (o.second >= c) {
      if (zml(b, o.first, o.second) == 0) {
        flag = 1;
      }
    }
  }
  return dp[a][b][c] = flag;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m;
  cin >> n >> m;
  while (m--) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    G[u].push_back({v, c});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      printf("%c", zml(i, j, 0) ? 'A' : 'B');
    }
    printf("\n");
  }
}
