#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
vector<pair<int, int> > ve[maxn];
int n, m;
int dp[maxn][maxn][maxn][3];
void init() {
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < m; i++) {
    int a, b;
    char s[10];
    scanf("%d%d", &a, &b);
    scanf("%s", s);
    int c = s[0] - 'a';
    ve[a].emplace_back(b, c);
  }
}
int dfs(int x, int y, int va, int turn) {
  if (dp[x][y][va][turn] != -1) return dp[x][y][va][turn];
  if (turn == 0) {
    for (int i = 0; i < ve[x].size(); i++) {
      pair<int, int> v = ve[x][i];
      if (v.second >= va)
        if (dfs(v.first, y, v.second, 1 - turn) == 0)
          return dp[x][y][va][turn] = 0;
    }
    return dp[x][y][va][turn] = 1;
  } else {
    for (int i = 0; i < ve[y].size(); i++) {
      pair<int, int> v = ve[y][i];
      if (v.second >= va)
        if (dfs(x, v.first, v.second, 1 - turn) == 1)
          return dp[x][y][va][turn] = 1;
    }
    return dp[x][y][va][turn] = 0;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, -1, 0))
        printf("B");
      else
        printf("A");
    }
    printf("\n");
  }
  return 0;
}
