#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, char> > g[100005];
long long DP[105][105][30][3];
long long n, m, k = 0, a[100005];
void input() {
  cin >> n >> m;
  for (long long i = 1; i <= m; ++i) {
    long long x, y;
    char c;
    cin >> x >> y >> c;
    g[x].push_back({y, c});
  }
  return;
}
long long dp(long long x, long long y, char z, long long turn) {
  if (DP[x][y][z][turn] > 0) return DP[x][y][z][turn];
  if (x == y) return DP[x][y][z][turn] = 1;
  long long check = 0;
  if (turn == 1) {
    if (g[x].size() == 0) return DP[x][y][z][turn] = 1;
    for (long long i = 0; i < g[x].size(); ++i) {
      long long u = g[x][i].first;
      long long v = g[x][i].second;
      if (z <= v) {
        DP[x][y][z][turn] = max(DP[x][y][z][turn], 3 - dp(u, y, v, 2));
        check = 1;
      }
    }
    if (check == 0) DP[x][y][z][turn] = 1;
  } else {
    if (g[y].size() == 0) return DP[x][y][z][turn] = 1;
    for (long long i = 0; i < g[y].size(); ++i) {
      long long u = g[y][i].first;
      long long v = g[y][i].second;
      if (z <= v) {
        DP[x][y][z][turn] = max(DP[x][y][z][turn], 3 - dp(x, u, v, 1));
        check = 1;
      }
    }
    if (check == 0) DP[x][y][z][turn] = 1;
  }
  return DP[x][y][z][turn];
}
void solve() {
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) {
      if (dp(i, j, 'a', 1) == 1)
        cout << 'B';
      else
        cout << 'A';
    }
    cout << endl;
  }
  return;
}
void output() { return; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  {
    input();
    solve();
    output();
  }
  return 0;
}
