#include <bits/stdc++.h>
using namespace std;
const int maxn = 110, alpha = 26;
int n, m;
int dp[maxn][maxn][alpha];
bool mark[maxn];
vector<int> ts;
vector<pair<int, int> > G[maxn];
void dfs(int a) {
  mark[a] = 1;
  for (pair<int, int> p : G[a]) {
    int b = p.first;
    if (!mark[b]) {
      dfs(b);
    }
  }
  ts.push_back(a);
}
int32_t main() {
  cin >> n >> m;
  for (int i = int(0); i < int(m); i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].push_back({b, c - 'a'});
  }
  for (int i = int(0); i < int(n); i++) {
    if (!mark[i]) {
      dfs(i);
    }
  }
  for (int size = int(0); size < int(2 * n - 1); size++) {
    for (int i = int(0); i < int(min(size + 1, n)); i++) {
      int j = size - i;
      if (j >= n) continue;
      int a = ts[i], b = ts[j];
      for (int x = int(0); x < int(alpha); x++) {
        for (pair<int, int> p : G[a]) {
          int ap = p.first, c = p.second;
          if (c >= x) dp[a][b][x] = max(dp[a][b][x], 1 - dp[b][ap][c]);
        }
      }
    }
  }
  for (int i = int(0); i < int(n); i++) {
    for (int j = int(0); j < int(n); j++) {
      cout << (dp[i][j][0] ? "A" : "B");
    }
    cout << endl;
  }
}
