#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
vector<pair<int, int> > a[maxn];
int dis[maxn][maxn][maxn];
int dfs(int u, int v, int p) {
  int ans = 0;
  if (dis[u][v][p] != -1 && p != -1) return dis[u][v][p];
  for (int i = 0; i < (int)a[u].size(); i++) {
    int x = a[u][i].first, y = a[u][i].second;
    if (p <= y) ans = ans | !dfs(v, x, y);
  }
  return dis[u][v][p] = ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(dis, -1, sizeof(dis));
  while (m--) {
    int x, y;
    char p[2];
    scanf("%d%d%s", &x, &y, p);
    a[x - 1].push_back(make_pair(y - 1, p[0] - 'a'));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dfs(i, j, -1))
        putchar('A');
      else
        putchar('B');
    }
    putchar('\n');
  }
}
