#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int A = 'z' - 'a' + 1;
int Dp[N][N][A][2], St[N];
vector<pair<int, int> > graf[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    scanf("%d %d %c", &a, &b, &c);
    graf[a].push_back({b, c - 'a'});
    St[b]++;
  }
  queue<int> kol;
  vector<int> topo;
  for (int i = 1; i < n + 1; i++)
    if (St[i] == 0) kol.push(i);
  while (!kol.empty()) {
    int v = kol.front();
    kol.pop();
    topo.push_back(v);
    for (auto s : graf[v])
      if ((--St[s.first]) == 0) kol.push(s.first);
  }
  reverse(topo.begin(), topo.end());
  for (int mux : topo)
    for (int lux : topo)
      for (int c = 0; c < A; c++) {
        for (auto s : graf[mux])
          if (s.second >= c) {
            Dp[mux][lux][c][0] |= (Dp[s.first][lux][s.second][1] ^ 1);
          }
        for (auto s : graf[lux])
          if (s.second >= c) {
            Dp[mux][lux][c][1] |= (Dp[mux][s.first][s.second][0] ^ 1);
          }
      }
  for (int mux = 1; mux < n + 1; mux++) {
    for (int lux = 1; lux < n + 1; lux++) {
      if (Dp[mux][lux][0][0])
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
}
