#include <bits/stdc++.h>
using namespace std;
int vis[110];
vector<int> order;
vector<vector<pair<char, int>>> G;
char ans[110][110];
void topsort(int n) {
  if (vis[n]) return;
  vis[n] = true;
  for (auto &p : G[n]) {
    topsort(p.second);
  }
  order.push_back(n);
}
void solve() {
  for (int i = 1; i < G.size(); i++) {
    topsort(i);
  }
  for (auto &v : G) {
    sort(v.rbegin(), v.rend());
  }
  for (auto i : order) {
    for (auto j : order) {
      for (auto pm : G[i]) {
        auto cm = pm.first;
        auto m = pm.second;
        bool win = true;
        for (auto pn : G[j]) {
          auto cn = pn.first;
          auto n = pn.second;
          if (cn >= cm && ans[m][n] < cn) {
            win = false;
            break;
          }
        }
        if (win) {
          ans[i][j] = cm;
          break;
        }
      }
    }
  }
}
int main() {
  int n, m, u, v;
  cin >> n >> m;
  char c;
  G.resize(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    G[u].push_back({c, v});
  }
  solve();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << (ans[i][j] ? 'A' : 'B');
    }
    cout << endl;
  }
}
