#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5, mod = 1e9 + 7;
vector<pair<int, char>> adj[N];
int dp[N][N][30][2];
bool solve(int a, int b, char l, int t) {
  if (dp[a][b][l - 'a'][t] != -1) return dp[a][b][l - 'a'][t];
  bool ret = false;
  if (!t) {
    for (auto i : adj[a])
      ret |= (i.second >= l && !solve(i.first, b, i.second, !t));
  } else {
    for (auto i : adj[b])
      ret |= (i.second >= l && !solve(a, i.first, i.second, !t));
  }
  return dp[a][b][l - 'a'][t] = ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, u, v;
  char c;
  cin >> n >> m;
  while (m--) {
    cin >> u >> v >> c;
    adj[u].emplace_back(v, c);
  }
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++, cout << '\n')
    for (int j = 1; j <= n; j++) cout << (solve(i, j, 'a', 0) ? 'A' : 'B');
  return 0;
}
