#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
const int maxm = 1000000 + 10;
const int mod = (int)1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = (1LL << 62);
const double eps = 1e-8;
const double PI = acos(-1.0);
int n, m;
int G[maxn][maxn];
int dp[maxn][maxn][30];
int get_dp(int u, int v, int c) {
  if (~dp[u][v][c]) return dp[u][v][c];
  for (int x = 1; x <= n; x++) {
    if (G[u][x] >= c && !get_dp(v, x, G[u][x])) return dp[u][v][c] = 1;
  }
  return dp[u][v][c] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(G, -1, sizeof(G));
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < m; i++) {
    int u, v;
    char s[5];
    scanf("%d%d%s", &u, &v, s);
    G[u][v] = s[0] - 'a';
  }
  for (int c = 25; ~c; c--) {
    for (int u = 1; u <= n; u++)
      for (int v = 1; v <= n; v++) dp[u][v][c] = get_dp(u, v, c);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dp[i][j][0])
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
