#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void fin() {}
const bool flag = 0;
const int N = 1e2 + 10;
vector<pii> adj[N];
bool dp[N][N][26], was[N][N][26];
bool calc(int u, int v, int c) {
  if (was[u][v][c]) {
    return dp[u][v][c];
  }
  was[u][v][c] = 1;
  dp[u][v][c] = 0;
  for (pii to : adj[u]) {
    if (to.second >= c && !calc(v, to.first, to.second)) {
      dp[u][v][c] = 1;
      break;
    }
  }
  return dp[u][v][c];
}
void ma1n() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    char c;
    cin >> c;
    adj[u].push_back({v, c - 'a'});
  }
  for (int i = 0; i < n; ++i, cout << "\n") {
    for (int j = 0; j < n; ++j) {
      cout << (calc(i, j, 0) ? 'A' : 'B');
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr), fin();
  int ts = 1;
  if (flag) {
    cin >> ts;
  }
  while (ts--) {
    ma1n();
  }
  return 0;
}
