#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > kraw[101];
int poz[101][101][27];
int post[1001];
int odw[1001];
int p = 0;
void dfs(int x) {
  odw[x] = 1;
  for (int i = 0; i < kraw[x].size(); i++) {
    if (odw[kraw[x][i].first] == 0) dfs(kraw[x][i].first);
  }
  p++;
  post[p] = x;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    char s[5];
    scanf("%d%d%s", &x, &y, s);
    kraw[x].push_back(make_pair(y, s[0]));
  }
  for (int i = 1; i <= n; i++)
    if (odw[i] == 0) dfs(i);
  for (int w = 25; w >= 0; w--)
    for (int a = 1; a <= n; a++)
      for (int b = a; b <= n; b++) {
        int czy = 0;
        int i = post[a];
        int j = post[b];
        for (int l = 0; l < kraw[i].size(); l++)
          if (kraw[i][l].second - 'a' >= w &&
              poz[j][kraw[i][l].first][kraw[i][l].second - 'a'] == 0)
            czy = 1;
        poz[i][j][w] = czy;
        czy = 0;
        for (int l = 0; l < kraw[j].size(); l++)
          if (kraw[j][l].second - 'a' >= w &&
              poz[i][kraw[j][l].first][kraw[j][l].second - 'a'] == 0)
            czy = 1;
        poz[j][i][w] = czy;
      }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (poz[i][j][0] == 1)
        printf("A");
      else
        printf("B");
    printf("\n");
  }
}
