#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int n, m;
int ans[N][N];
int dp[N][N][26];
int a[101][101];
int kt[N];
int cal(int u, int v, int c) {
  if (dp[u][v][c] >= 0) return dp[u][v][c];
  dp[u][v][c] = 0;
  for (int i = 1; i <= n; ++i)
    if (a[u][i] != -1 && c <= a[u][i]) {
      dp[u][v][c] |= cal(v, i, a[u][i]) ^ 1;
    }
  return dp[u][v][c];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) a[i][j] = -1;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    a[x][y] = c - 'a';
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int c = 0; c < 26; ++c) dp[i][j][c] = -1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      int cur = cal(i, j, 0);
      if (!cur)
        cout << "B";
      else
        cout << "A";
    }
    cout << '\n';
  }
}
