#include <bits/stdc++.h>
using namespace std;
int n, m;
int d[200][200][27];
int w[200][200];
int deg[200];
void Do(int x, int y) {
  for (int i = 1; i <= 26; i++) {
    for (int j = 1; j <= n; j++) {
      if (w[x][j] < i) continue;
      if (!d[y][j][w[x][j]]) d[x][y][i] = 1;
    }
  }
}
struct fast_que {
  int head, tail;
  int arr[2000];
  int size() { return tail - head + 1; }
  bool empty() { return head > tail; }
  void init() {
    head = 0;
    tail = -1;
    memset(arr, 0, sizeof(arr));
  }
  void pop() { head++; }
  int front() { return arr[head]; }
  void push(int x) {
    tail++;
    arr[tail] = x;
  }
};
int a, b;
char c;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> c;
    deg[b]++;
    w[a][b] = c - 'a' + 1;
  }
  fast_que q;
  q.init();
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 1; i <= n; i++)
      if (w[x][i] != 0) {
        deg[i]--;
        if (deg[i] == 0) q.push(i);
      }
  }
  for (int i = q.tail; i >= 0; i--) {
    for (int j = q.tail; j > i; j--) Do(q.arr[i], q.arr[j]);
    for (int j = q.tail; j > i; j--) Do(q.arr[j], q.arr[i]);
    Do(q.arr[i], q.arr[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (d[i][j][1])
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
