#include <bits/stdc++.h>
using namespace std;
int dp[300][300][50];
int vis[300][300][50];
vector<pair<int, int> > g[2000];
int val[30000];
int who_wins(int p1, int p2, int ch) {
  if (vis[p1][p2][ch] == 1) return dp[p1][p2][ch];
  int val = 0;
  int flg = 0;
  for (int i = 0; i < g[p1].size(); i++) {
    if (g[p1][i].second >= ch) {
      int xx = who_wins(p2, g[p1][i].first, g[p1][i].second);
      if (xx == 0) flg = 1;
    }
  }
  vis[p1][p2][ch] = 1;
  dp[p1][p2][ch] = flg;
  return dp[p1][p2][ch];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    string s;
    cin >> a >> b >> s;
    int val = s[0] - 'a';
    g[a].push_back(make_pair(b, val));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (who_wins(i, j, 0) == 0)
        cout << "B";
      else
        cout << "A";
    }
    cout << endl;
  }
  return 0;
}
