#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> vt;
int dp[110][110][2][26];
int n, m;
int func(int here, int here1, int ch, int ch1) {
  int &ret = dp[here][here1][ch][ch1];
  if (ret != -1) return ret;
  if (ch == 0) {
    ret = 1;
    for (int i = 0; i < vt[here].size(); i++) {
      int next = vt[here][i].first;
      int ncst = vt[here][i].second;
      if (ncst >= ch1) ret = min(ret, func(next, here1, ch ^ 1, ncst));
    }
  } else {
    ret = 0;
    for (int i = 0; i < vt[here1].size(); i++) {
      int next = vt[here1][i].first;
      int ncst = vt[here1][i].second;
      if (ncst >= ch1) ret = max(ret, func(here, next, ch ^ 1, ncst));
    }
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d %d", &n, &m);
  vt.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int q, w;
    char e;
    scanf("%d %d %c", &q, &w, &e);
    int x = e - 'a';
    vt[q].push_back({w, x});
  }
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= n; y++) {
      int t = func(i, y, 0, 0);
      if (t)
        printf("B");
      else
        printf("A");
    }
    printf("\n");
  }
}
