#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > g[103];
int win[103][103][26];
int dfs(int x, int y, int q) {
  if (win[x][y][q] != -1) return win[x][y][q];
  win[x][y][q] = 0;
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i].second < q) continue;
    if (dfs(y, g[x][i].first, g[x][i].second) == 0) {
      win[x][y][q] = 1;
      return 1;
    }
  }
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    g[x].push_back(make_pair(y, c - 'a'));
  }
  memset(win, -1, sizeof(win));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cout << char('B' - dfs(i, j, 0));
    cout << endl;
  }
}
