#include <bits/stdc++.h>
using namespace std;
int sum = 0, m, tmp = 0, tmp2 = 0, comb = 0;
vector<int> ts, deg, q, check, rts;
vector<vector<pair<int, char>>> g, dp;
long long int n, k, con;
char c;
int b = 0;
int main() {
  cin >> n >> m;
  g.resize(n + 1);
  deg.resize(n + 1, 0);
  ts.resize(n + 1);
  dp.resize(n + 1);
  check.resize(n + 1, 0);
  rts.resize(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> tmp >> tmp2 >> c;
    g[tmp].push_back(pair<int, char>(tmp2, c));
    deg[tmp2]++;
  }
  int j = 0, num = n;
  for (int i = 1; i <= n; i++) {
    dp[i].resize(n + 1, pair<int, char>(0, NULL));
    if (deg[i] == 0 && check[i] == 0) q.push_back(i);
    while (j < q.size()) {
      ts[q[j]] = num;
      rts[num--] = q[j];
      for (int k = 0; k < g[q[j]].size(); k++) {
        if (check[g[q[j]][k].first] == 0) {
          deg[g[q[j]][k].first]--;
          if (deg[g[q[j]][k].first] == 0) {
            q.push_back(g[q[j]][k].first);
            check[g[q[j]][k].first] = 1;
          }
        }
      }
      j++;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k < g[rts[i]].size(); k++) {
        b = 0;
        for (int l = 0; l < g[rts[j]].size(); l++) {
          if (g[rts[i]][k].second <= g[rts[j]][l].second &&
              dp[ts[g[rts[i]][k].first]][ts[g[rts[j]][l].first]].second <
                  g[rts[j]][l].second) {
            b = 1;
            break;
          }
        }
        if (b == 0)
          dp[i][j] =
              pair<int, char>(1, max(dp[i][j].second, g[rts[i]][k].second));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dp[ts[i]][ts[j]].first == 1)
        cout << 'A';
      else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
