#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > e[105];
int win[105][105][26];
inline int in() {
  int x;
  cin >> x;
  return x;
}
bool get(int x, int y, int last) {
  int &ok = win[x][y][last];
  if (ok != -1) return ok;
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i].second >= last)
      if (!get(y, e[x][i].first, e[x][i].second)) return ok = 1;
  return ok = 0;
}
int main() {
  n = in();
  m = in();
  memset(win, -1, sizeof(win));
  for (int i = 0; i < m; i++) {
    int x = in() - 1, y = in() - 1;
    char c;
    cin >> c;
    e[x].push_back(make_pair(y, c - 'a'));
  }
  for (int i = 0; i < n; i++, puts(""))
    for (int j = 0; j < n; j++) cout << char('B' - get(i, j, 0));
  return 0;
}
