#include <bits/stdc++.h>
using namespace std;
const int N = 100;
vector<pair<int, int> > adj[N + 2];
int mem[N + 2][N + 2][30];
bool f(int a, int b, int lst) {
  if (~mem[a][b][lst]) return mem[a][b][lst];
  for (int i = 0; i < (int)adj[a].size(); i++) {
    if (adj[a][i].second < lst) continue;
    int &win = mem[a][b][lst];
    win = 1;
    for (int j = 0; j < (int)adj[b].size(); j++) {
      if (adj[b][j].second < adj[a][i].second) continue;
      if (!f(adj[a][i].first, adj[b][j].first, adj[b][j].second)) win = 0;
    }
    if (win) return 1;
  }
  return 0;
}
int main() {
  memset(mem, -1, sizeof mem);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    adj[u].push_back(make_pair(v, c - 'a'));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (f(i, j, 0)) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << endl;
  }
}
