#include <bits/stdc++.h>
using namespace std;
int static_init = []() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
  return 0;
}();
constexpr int N = 100;
int n;
int8_t a[N][N];
bool run(int i, int j, int c) {
  static bool dp[N][N][27], v[N][N][27];
  if (!v[i][j][c]) {
    v[i][j][c] = true;
    for (int k = 0; k < n; k++) {
      if (a[i][k] >= c && !run(j, k, a[i][k])) {
        dp[i][j][c] = true;
        break;
      }
    }
  };
  return dp[i][j][c];
}
int main() {
  int m, v, u;
  cin >> n >> m;
  while (m-- > 0) {
    char c[2];
    cin >> v >> u >> c;
    a[v - 1][u - 1] = c[0] - '`';
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << (run(i, j, 1) ? 'A' : 'B');
    cout << '\n';
  }
  return 0;
}
