#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
using namespace std;
using ii = pair<int, char>;
const int N = 105;
int n, m, f[N][N][30];
vector<ii> adj[N];
int calc(int u, int v, int c) {
  if (f[u][v][c]) return f[u][v][c];
  if (adj[u].empty()) return (f[u][v][c] = 2);
  for (ii e : adj[u]) {
    if (c <= e.second && calc(v, e.first, e.second) == 2)
      return (f[u][v][c] = 1);
  }
  return (f[u][v][c] = 2);
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    adj[u].emplace_back(v, (c - 'a'));
  }
  for (int u = 1; u <= n; ++u) {
    for (int v = 1; v <= n; ++v) {
      cout << ((calc(u, v, 0) == 1) ? 'A' : 'B');
    }
    cout << "\n";
  }
  return 0;
}
