#include <bits/stdc++.h>
using namespace std;
string s;
vector<pair<int, int> > edge[103];
int wi[104][104][171];
int getwin(int x, int y, int c) {
  if (wi[x][y][c] != -1) return wi[x][y][c];
  int win = 0;
  for (pair<int, int> v : edge[x]) {
    if (v.second >= c)
      if (getwin(y, v.first, v.second) == 0) {
        win = 1;
        break;
      }
  }
  return wi[x][y][c] = win;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      for (int x = 0; x < 170; ++x) wi[i][j][x] = -1;
  char c;
  int v;
  int u;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v >> c;
    --u;
    --v;
    edge[u].push_back(make_pair(v, c));
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j)
      if (getwin(i, j, 0))
        cout << "A";
      else
        cout << "B";
    cout << '\n';
  }
}
