#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, int>;
const int mod = 1e9 + 7, INF = 1 << 30;
const double EPS = 1e-12, PI = 3.1415926535897932384626;
const ll LINF = 1LL << 60, lmod = 1e9 + 7;
const int MAX_N = 102;
vector<P> graph[MAX_N];
int memo[2][MAX_N][MAX_N][30];
int solve(bool is_first, int a, int b, int score) {
  if (memo[int(is_first)][a][b][score] != -1)
    return memo[int(is_first)][a][b][score];
  if (is_first) {
    bool win = false;
    for (auto p : graph[a]) {
      int u, c;
      tie(u, c) = p;
      if (c >= score) {
        win |= (solve(false, u, b, c) == 1);
      }
    }
    if (!win)
      return memo[int(is_first)][a][b][score] = 0;
    else
      return memo[int(is_first)][a][b][score] = 1;
  } else {
    bool win = true;
    for (auto p : graph[b]) {
      int u, c;
      tie(u, c) = p;
      if (c >= score) {
        win &= (solve(true, a, u, c) == 1);
      }
    }
    if (win)
      return memo[int(is_first)][a][b][score] = 1;
    else
      return memo[int(is_first)][a][b][score] = 0;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    a--;
    b--;
    graph[a].push_back(P(b, int(c - 'a')));
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < MAX_N; j++)
      for (int k = 0; k < MAX_N; k++)
        for (int l = 0; l < 30; l++) memo[i][j][k][l] = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) cout << (solve(true, i, j, 0) == 1 ? 'A' : 'B');
    cout << "" << endl;
  }
  return 0;
}
