#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 9;
int N, M;
vector<pair<int, int>> g[maxn];
bool vis[maxn][maxn][2][26], dp[maxn][maxn][2][26];
bool dfs(int a, int b, int cur, int val) {
  if (vis[a][b][cur][val]) {
    return dp[a][b][cur][val];
  }
  vis[a][b][cur][val] = true;
  if (cur == 0) {
    for (auto e : g[a]) {
      if (e.second >= val && !dfs(e.first, b, 1, e.second)) {
        return dp[a][b][cur][val] = true;
      }
    }
  } else {
    for (auto e : g[b]) {
      if (e.second >= val && !dfs(a, e.first, 0, e.second)) {
        return dp[a][b][cur][val] = true;
      }
    }
  }
  return dp[a][b][cur][val] = false;
}
int main() {
  cin >> N >> M;
  while (M--) {
    int u, v;
    char c;
    scanf("%d%d %c", &u, &v, &c);
    g[--u].push_back(make_pair(--v, c - 'a'));
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      putchar(dfs(i, j, 0, 0) ? 'A' : 'B');
    }
    puts("");
  }
  return 0;
}
