#include <bits/stdc++.h>
using namespace std;
const int maxn = (100 * 100) * 27 * 2 + 5;
int n, m, head[101], kl, maxx, ind[maxn], opt;
int T, top, x, y, c[maxn], f[maxn], flg, a;
struct line {
  int fr, to, next, val;
} q[101 * 101];
void pushline(int x, int y, int z) {
  q[++kl].next = head[x];
  head[x] = kl;
  q[kl].to = y;
  q[kl].val = z;
}
vector<int> g[maxn];
void topsort() {
  stack<int> stk;
  for (int i = 1; i <= maxx; i++)
    if (ind[i] == 0) stk.push(i);
  while (!stk.empty()) {
    int x = stk.top();
    stk.pop();
    c[++top] = x;
    for (int v : g[x]) {
      ind[v]--;
      if (ind[v] == 0) stk.push(v);
    }
  }
}
int get(int x, int y, int k, int type) {
  int id = 54 * (n * (x - 1) + (y - 1)) + 2 * (k - 1) + type + 1;
  maxx = max(maxx, id);
  return id;
}
void link(int x, int y, int k, int type) {
  if (type == 0)
    for (int p = head[x]; int v = q[p].to; p = q[p].next) {
      int id = get(v, y, q[p].val, type ^ 1);
      if (q[p].val < k)
        continue;
      else
        g[get(x, y, k, type)].push_back(id), ind[id]++;
    }
  else
    for (int p = head[y]; int v = q[p].to; p = q[p].next) {
      int id = get(x, v, q[p].val, type ^ 1);
      if (q[p].val < k)
        continue;
      else
        g[get(x, y, k, type)].push_back(id), ind[id]++;
    }
}
char z;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    pushline(x, y, z - 'a' + 2);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= 27; k++)
        for (int p = 0; p <= 1; p++) link(i, j, k, p);
  topsort();
  for (int x = top; x >= 1; x--) {
    for (int v : g[c[x]])
      if (f[v] == 0) {
        f[c[x]] = 1;
        break;
      }
  }
  for (int i = 1; i <= n; i++, cout << endl)
    for (int j = 1; j <= n; j++) {
      if (f[get(i, j, 1, 0)])
        cout << "A";
      else
        cout << "B";
    }
  return 0;
}
