#include <bits/stdc++.h>
using namespace std;
const int W = 1;
const int L = 2;
int n, m;
vector<vector<pair<int, int>>> a;
int d[101][101][26];
int win(int x, int y, int mi) {
  if (d[x][y][mi]) return d[x][y][mi];
  for (pair<int, int> p : a[x]) {
    int to = p.first;
    int ch = p.second;
    if (ch < mi) continue;
    if (win(y, to, ch) == L) {
      return d[x][y][mi] = W;
    }
  }
  return d[x][y][mi] = L;
}
int main() {
  cin >> n >> m;
  a.resize(n);
  for (int i = (0); i < (m); ++i) {
    int q, w;
    char c;
    cin >> q >> w >> c;
    --q, --w;
    a[q].push_back(make_pair(w, c - 'a'));
  }
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      if (win(i, j, 0) == W) {
        cout << 'A';
      } else {
        cout << 'B';
      }
    }
    cout << endl;
  }
  return 0;
}
