#include <bits/stdc++.h>
using namespace std;
struct node {
  int v, w;
  node() {}
  node(int V, int W) {
    v = V;
    w = W;
  }
};
vector<node> G[105];
int n, m;
int dp[105][105][30];
int dfs(int first, int second, int s) {
  if (dp[first][second][s] != -1) return dp[first][second][s];
  for (int i = 0; i < G[first].size(); i++) {
    int v = G[first][i].v;
    int w = G[first][i].w;
    if (w < s) continue;
    if (dfs(second, v, w) == 0) return dp[first][second][s] = 1;
  }
  return dp[first][second][s] = 0;
}
int main() {
  while (~scanf("%d %d", &n, &m)) {
    memset(dp, -1, sizeof(dp));
    for (int i = 1; i <= n; i++) G[i].clear();
    for (int i = 1; i <= m; i++) {
      int u, v;
      char s;
      scanf("%d %d %c", &u, &v, &s);
      G[u].push_back(node(v, s - 'a'));
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++)
        if (dfs(i, j, 0))
          printf("A");
        else
          printf("B");
      printf("\n");
    }
  }
  return 0;
}
