#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u;
  int v;
  int w;
  edge() : u(0), v(0), w(0) {}
  edge(int _u, int _v, int _w) : u(_u), v(_v), w(_w) {}
};
vector<edge> G[200];
int state[101][101][30];
int deg[101][101];
queue<pair<int, int>> q;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    scanf("%d %d %c", &a, &b, &c);
    G[b].push_back(edge(b, a, c - 'a'));
    for (int j = 1; j <= n; j++) deg[a][j]++;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (deg[i][j] == 0) {
        q.push(make_pair(i, j));
      }
    }
  }
  while (!q.empty()) {
    int A = q.front().first;
    int B = q.front().second;
    q.pop();
    int u = B;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i].v;
      int w = G[u][i].w;
      for (int j = 0; j <= w; j++) {
        if (state[v][A][j] == 0 && state[A][B][w] == 0) {
          state[v][A][j] = 1;
        }
      }
      deg[v][A]--;
      if (deg[v][A] == 0) {
        q.push(make_pair(v, A));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (state[i][j][0] == 1) {
        cout << 'A';
      } else {
        cout << 'B';
      }
    }
    cout << endl;
  }
}
