#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int I = 1e2 + 2;
const int J = 28;
const LL mod = 1e9 + 7, inf = 9e18;
int dp[I][I][J];
vector<pair<int, int>> adj[I];
int go(int u, int v, int w = 0) {
  int &ret = dp[u][v][w];
  if (ret != -1) return ret;
  int win = 0;
  for (auto x : adj[u]) {
    if (x.second < w) continue;
    win |= go(v, x.first, x.second);
  }
  return (ret = 1 - win);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    char ch;
    cin >> ch;
    adj[u].emplace_back(make_pair(v, int(ch - 'a' + 1)));
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cout << (go(i, j) == 1 ? 'B' : 'A');
    }
    cout << '\n';
  }
  return 0;
}
