#include <bits/stdc++.h>
using namespace std;
const int Inf = (int)1e9 + 7;
namespace {
const int N = 107;
int n, m;
vector<pair<int, int> > gr[N];
int res[N][N];
int memo[N][N][26][2];
int win(int a, int b, int last, int turn) {
  int& res = memo[a][b][last][turn];
  if (res != 0) return res;
  if (turn == 0) {
    for (auto x : gr[a])
      if (x.second >= last) {
        if (win(x.first, b, x.second, 1 - turn) == -1) return res = 1;
      }
    return res = -1;
  } else {
    for (auto x : gr[b])
      if (x.second >= last) {
        if (win(a, x.first, x.second, 1 - turn) == -1) return res = 1;
      }
    return res = -1;
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char w;
    cin >> a >> b >> w;
    --a, --b;
    gr[a].emplace_back(make_pair(b, w - 'a'));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (win(i, j, 0, 0) == -1) {
        res[i][j] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << (res[i][j] == 0 ? "A" : "B");
    cout << "\n";
  }
}
}  // namespace
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(9);
  cout << fixed;
  solve();
  return 0;
}
