#include <bits/stdc++.h>
struct GraphList {
  int dest;
  char ch;
  struct GraphList *next;
};
void StaviNaPoc(struct GraphList **p, int d, char c) {
  struct GraphList *q = (struct GraphList *)malloc(sizeof(struct GraphList));
  q->ch = c;
  q->dest = d;
  q->next = *p;
  *p = q;
}
struct GraphList *Adj[101];
int dp[101][101][26];
int f(int a, int b, int c) {
  int res;
  if (dp[a][b][c] != -1)
    return dp[a][b][c];
  else if (a == b) {
    dp[a][b][c] = 0;
    return dp[a][b][c];
  } else {
    res = 0;
    struct GraphList *q = Adj[a];
    while (q != NULL) {
      if ((q->ch - 'a') >= c) {
        if (f(b, q->dest, q->ch - 'a') == 0) res = 1;
      }
      q = q->next;
    }
    dp[a][b][c] = res;
    return res;
  }
}
int main() {
  int n, m, a, b;
  char c;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) Adj[i] = NULL;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %c", &a, &b, &c);
    StaviNaPoc(&Adj[a], b, c);
  }
  for (int i = 1; i <= 100; i++)
    for (int j = 1; j <= 100; j++)
      for (int k = 0; k < 26; k++) dp[i][j][k] = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (f(i, j, 0) == 1)
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
