#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long v, c;
};
struct node {
  vector<edge> adj;
};
vector<node> graph;
int dp[105][105][26];
bool solve(long long u, long long v, long long last_char) {
  if (dp[u][v][last_char] != -1) {
    return dp[u][v][last_char] == 0;
  }
  bool i_win = false;
  long long i, next_node, next_char;
  for (i = 0; i < graph[u].adj.size(); i++) {
    next_node = graph[u].adj[i].v;
    next_char = graph[u].adj[i].c;
    if (next_char >= last_char and !solve(v, next_node, next_char)) {
      i_win = true;
    }
  }
  dp[u][v][last_char] = i_win ? 0 : 1;
  return i_win;
}
int main() {
  long long i, j, k, t, n, e, u, v;
  char c;
  scanf("%lld", &n);
  scanf("%lld", &e);
  graph.resize(n + 1);
  for (i = 0; i < e; i++) {
    scanf("%lld", &u);
    scanf("%lld", &v);
    cin >> c;
    graph[u].adj.push_back(edge{v, c - 'a'});
  }
  for (i = 0; i < n + 1; i++) {
    for (j = 0; j < n + 1; j++) {
      for (k = 0; k < 26; k++) dp[i][j][k] = -1;
    }
  }
  for (i = 1; i < n + 1; i++) {
    for (j = 1; j < n + 1; j++) {
      if (solve(i, j, 0)) {
        printf("A");
      } else {
        printf("B");
      }
    }
    printf("\n");
  }
  return 0;
}
