#include <bits/stdc++.h>
using namespace std;
long long gcd1(long long a, long long b) {
  if (a == 0) return b;
  return gcd1(b % a, a);
}
long long modx(long long base, long long ex) {
  long long ans = 1LL, val = base;
  while (ex > 0LL) {
    if (ex & 1LL) ans = (ans * val) % 998244353LL;
    val = (val * val) % 998244353LL;
    ex = ex >> 1LL;
  }
  return ans;
}
const int maxn = 105;
vector<pair<int, int> > adj[maxn];
bool visit[maxn][maxn][26], dp[maxn][maxn][26];
int n, m, x, y;
char c;
bool dfs(int start1, int start2, int ch) {
  if (visit[start1][start2][ch]) return dp[start1][start2][ch];
  visit[start1][start2][ch] = true;
  for (int i = 0; i < adj[start1].size(); i++) {
    int pt = adj[start1][i].first;
    int c = adj[start1][i].second;
    if (c < ch)
      continue;
    else {
      bool temp = dfs(start2, pt, c);
      if (!temp) return dp[start1][start2][ch] = true;
    }
  }
  return dp[start1][start2][ch] = false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> c;
    adj[x].push_back(make_pair(y, c - 'a'));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0))
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
