#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<int> > > dp;
vector<vector<pair<int, int> > > ed;
int f(int g, int h, int l) {
  int &res = dp[g][h][l];
  if (res != -1) return res;
  res = 0;
  for (int i = 0; i < ed[g].size(); i++) {
    pair<int, int> p = ed[g][i];
    int y = p.first;
    int z = p.second;
    if (z >= l) {
      int val = f(h, y, z);
      if (val == 0) {
        res = 1;
        return res;
      }
    }
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  ed.resize(n + 1);
  int x, y, z;
  char ch;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> ch;
    int z = ch - 'a';
    ed[x].push_back(pair<int, int>(y, z));
  }
  dp.resize(n + 1, vector<vector<int> >(n + 1, vector<int>(26, -1)));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int res = f(i, j, 0);
      if (res == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
}
