#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int dp[N][N][26], n, m;
vector<pair<int, int> > g[N];
int solve(int i, int j, int c) {
  int &r = dp[i][j][c];
  if (r != -1) return r;
  r = 0;
  for (auto e : g[i])
    if (e.second >= c) r |= !solve(j, e.first, e.second);
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int x = 0, qwert = m; x < qwert; x++) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    u--;
    v--;
    g[u].push_back({v, c - 'a'});
  }
  for (int x = 0, qwert = n; x < qwert; x++) {
    for (int y = 0, qwert = n; y < qwert; y++)
      cout << (char)('A' + !solve(x, y, 0));
    cout << "\n";
  }
}
