#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, m;
struct Edge {
  int to;
  char x;
  Edge(int a = 0, char x = ' ') : to(a), x(x) {}
};
vector<Edge> G[maxn];
int dp[maxn][maxn][26];
void dfs(int u, int v, int c) {
  if (dp[u][v][c] != -1) return;
  dp[u][v][c] = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int to = G[u][i].to;
    int x = G[u][i].x - 'a';
    if (x < c) continue;
    dfs(v, to, x);
    if (dp[v][to][x] == 0) dp[u][v][c] = 1;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    char c[2];
    scanf("%d%d%s", &a, &b, c);
    G[a].push_back(Edge(b, c[0]));
  }
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dfs(i, j, 0);
      putchar('A' + (dp[i][j][0] ^ 1));
    }
    putchar('\n');
  }
  return 0;
}
