#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 105;
int dp[N][N][26];
vector<pair<int, int> > G[N];
int DP(int x, int y, int ch) {
  if (dp[x][y][ch] != -1) return dp[x][y][ch];
  int &ans = dp[x][y][ch];
  ans = 0;
  for (int k = 0; k < (int((G[x]).size())); k++) {
    if (G[x][k].second < ch) continue;
    bool flag = 0;
    for (int i = 0; i < (int((G[y]).size())) && !flag; i++) {
      if (G[y][i].second < G[x][k].second) continue;
      int vy = G[y][i].first;
      int vx = G[x][k].first;
      if (DP(vx, vy, G[y][i].second) == 0) flag = true;
    }
    if (flag == 0) {
      dp[x][y][ch] = 1;
      break;
    }
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    char ch;
    scanf("%d %d %c", &u, &v, &ch);
    G[u].push_back(pair<int, int>(v, ch - 'a'));
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++, puts(""))
    for (int j = 1; j <= n; j++)
      if (DP(i, j, 0))
        putchar('A');
      else
        putchar('B');
}
