#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m;
vector<pair<int, char> > e[111];
bool dp[2][111][111][26] = {};
bool vis[2][111][111][26] = {};
bool rec(int i, int j, char c, int r) {
  if (vis[r][i][j][c]) return dp[r][i][j][c];
  bool ans;
  vis[r][i][j][c] = true;
  if (r == 0) {
    int sz = e[i].size();
    ans = true;
    for (int k = 0; k < sz; k++) {
      if (e[i][k].second >= c) {
        ans &= rec(e[i][k].first, j, e[i][k].second, 1);
      }
    }
  } else {
    int sz = e[j].size();
    ans = false;
    for (int k = 0; k < sz; k++) {
      if (e[j][k].second >= c) {
        ans |= rec(i, e[j][k].first, e[j][k].second, 0);
      }
    }
  }
  return dp[r][i][j][c] = ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    char c;
    scanf("%d%d %c", &u, &v, &c);
    e[u].push_back({v, c - 'a'});
  }
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      rec(i, j, 0, 0);
      if (!dp[0][i][j][0])
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
}
