#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > E[123];
int f[123][123][30][2];
int dfs(int x, int y, int ch, int turn) {
  if (f[x][y][ch][turn] != -1) return f[x][y][ch][turn];
  if (turn == 0) {
    for (auto p : E[x]) {
      int u = p.first;
      int tmp = p.second;
      if (tmp >= ch) {
        if (dfs(u, y, tmp, 1) == 0) return f[x][y][ch][turn] = 0;
      }
    }
    return f[x][y][ch][turn] = 1;
  } else {
    for (auto p : E[y]) {
      int u = p.first;
      int tmp = p.second;
      if (tmp >= ch) {
        if (dfs(x, u, tmp, 0) == 1) return f[x][y][ch][turn] = 1;
      }
    }
    return f[x][y][ch][turn] = 0;
  }
}
int main() {
  ios::sync_with_stdio(false);
  char c;
  int n, m, u, v;
  cin >> n >> m;
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> c;
    E[u].push_back(make_pair(v, c - 'a'));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!dfs(i, j, 0, 0))
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
