#include <bits/stdc++.h>
using namespace std;
const int maxn = 107;
int G[maxn][maxn], sg[maxn][maxn][30][2];
int _max[maxn];
int n, m;
void dfs(int p1, int p2, int cost, int step) {
  if (sg[p1][p2][cost][step] != 0) return;
  if (step == 1) {
    bool allfail = true;
    for (int i = 1; i <= n; i++) {
      if (G[p1][i] >= cost) {
        dfs(i, p2, G[p1][i], step ^ 1);
        if (sg[i][p2][G[p1][i]][step ^ 1] == -1) allfail = false;
      }
    }
    if (allfail) {
      sg[p1][p2][cost][step] = -1;
    } else
      sg[p1][p2][cost][step] = 1;
  } else {
    bool allfail = true;
    for (int i = 1; i <= n; i++) {
      if (G[p2][i] >= cost) {
        dfs(p1, i, G[p2][i], step ^ 1);
        if (sg[p1][i][G[p2][i]][step ^ 1] == -1) allfail = false;
      }
    }
    if (allfail) {
      sg[p1][p2][cost][step] = -1;
    } else
      sg[p1][p2][cost][step] = 1;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      G[i][j] = -1;
    }
  }
  for (int i = 1; i <= m; i++) {
    int v, u;
    char ch;
    scanf("%d%d %c", &v, &u, &ch);
    G[v][u] = ch - 'a' + 2;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dfs(i, j, 0, 1);
      if (sg[i][j][0][1] == 1)
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
