#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100;
const int SIGMA = 26;
int d[NMAX + 2][NMAX + 2][SIGMA + 2];
bool viz[NMAX + 2][NMAX + 2][SIGMA + 2];
vector<pair<int, int>> G[NMAX + 2], GP[NMAX + 2];
int outdeg[NMAX + 2], timp[NMAX + 2], timp_ind = 0;
vector<int> sortop;
int N, M;
void make_sortop() {
  queue<int> Q;
  for (int i = 1; i <= N; ++i) {
    if (!outdeg[i]) Q.push(i);
  }
  while (!Q.empty()) {
    int nod = Q.front();
    sortop.push_back(nod);
    timp[++timp_ind] = nod;
    Q.pop();
    for (auto pp : GP[nod]) {
      int x = pp.first;
      outdeg[x]--;
      if (outdeg[x] == 0) {
        Q.push(x);
      }
    }
  }
}
bool solve(int x, int y, int c = 0) {
  if (viz[x][y][c]) return d[x][y][c];
  bool can_win = 0;
  for (auto pp : G[x]) {
    int z = pp.first;
    int c2 = pp.second;
    if (c2 < c) continue;
    if (!solve(y, z, c2)) {
      can_win = 1;
      break;
    }
  }
  viz[x][y][c] = 1;
  return (d[x][y][c] = can_win);
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= M; ++i) {
    int x, y;
    char ch;
    cin >> x >> y >> ch;
    G[x].push_back({y, (int)(ch - 'a')});
    GP[y].push_back({x, (int)(ch - 'a')});
    outdeg[x]++;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      bool ok = solve(i, j);
      if (ok)
        cout << "A";
      else
        cout << "B";
    }
    cout << '\n';
  }
  return 0;
}
