#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
inline bool read(int& val) { return scanf("%d", &val) != -1; }
inline bool read(double& val) { return scanf("%lf", &val) != -1; }
inline bool read(char* val) { return scanf("%s", val) != -1; }
template <class T1, class T2>
inline bool read(T1& a, T2& b) {
  return read(a) && read(b);
}
template <class T1, class T2, class T3>
inline bool read(T1& a, T2& b, T3& c) {
  return read(a) && read(b) && read(c);
}
template <class T1, class T2, class T3, class T4>
inline bool read(T1& a, T2& b, T3& c, T4& d) {
  return read(a) && read(b) && read(c) && read(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e) {
  return read(a) && read(b) && read(c) && read(d) && read(e);
}
const int N = 111;
struct edge {
  int u, v, c;
};
vector<edge> to[N];
int dp[N][N][128];
char str[N];
bool dfs(int a, int b, int c) {
  if (dp[a][b][c] == -1) {
    dp[a][b][c] = false;
    for (edge e : to[a])
      if (e.c >= c) {
        if (!dfs(b, e.v, e.c)) dp[a][b][c] = true;
      }
  }
  return dp[a][b][c];
}
int main() {
  int n, m;
  read(n, m);
  for (int i = 0, _ = (m); i < _; ++i) {
    edge e;
    char str[10];
    read(e.u, e.v, str);
    e.c = str[0];
    e.u--;
    e.v--;
    to[e.u].push_back(e);
  }
  memset(dp, -1, sizeof(dp));
  for (int a = 0, _ = (n); a < _; ++a)
    for (int b = 0, _ = (n); b < _; ++b) dfs(a, b, 0);
  for (int a = 0, _ = (n); a < _; ++a) {
    for (int b = 0, _ = (n); b < _; ++b) printf("%c", dp[a][b][0] ? 'A' : 'B');
    printf("\n");
  }
  return 0;
}
