#include <bits/stdc++.h>
using namespace std;
inline void Fail() {
  printf("0");
  exit(0);
}
inline void debug(int x) { cerr << "debug: " << x << "\n"; }
inline void debug(int n, int x[]) {
  cerr << "debug "
       << "\n";
  for (int(i) = 0; (i) < n; i++) cerr << x[i] << " ";
  cerr << "\n";
}
inline void debug(string x) { cerr << "debug: " << x << "\n"; }
const int maxn = 105;
const int maxm = 30;
int n, m;
char c[maxn];
int deg[maxn], q[maxn];
vector<pair<int, int> > edge[maxn];
int dp[maxn][maxn][maxm][2];
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = 0; (i) < m; i++) {
    int u, v;
    scanf("%d%d%s", &u, &v, c);
    u--;
    v--;
    edge[u].push_back(make_pair(v, c[0] - 'a'));
    deg[v]++;
  }
  int l = 0, r = 0;
  for (int(i) = 0; (i) < n; i++)
    if (!deg[i]) q[r++] = i;
  while (l < r) {
    int x = q[l++];
    for (int(i) = 0; (i) < edge[x].size(); i++) {
      pair<int, int> y = edge[x][i];
      deg[y.first]--;
      if (!deg[y.first]) q[r++] = y.first;
    }
  }
  for (int i = r - 1; i >= 0; i--)
    for (int j = r - 1; j >= 0; j--)
      for (int(k) = 0; (k) < 26; k++) {
        int x = q[i], y = q[j];
        int &res0 = dp[x][y][k][0], &res1 = dp[x][y][k][1];
        res0 = res1 = -1;
        for (int(ii) = 0; (ii) < edge[x].size(); ii++) {
          pair<int, int> jj = edge[x][ii];
          if (jj.second >= k && dp[jj.first][y][jj.second][1] == 0) res0 = 0;
        }
        if (res0 < 0) res0 = 1;
        for (int(ii) = 0; (ii) < edge[y].size(); ii++) {
          pair<int, int> jj = edge[y][ii];
          if (jj.second >= k && dp[x][jj.first][jj.second][0] == 1) res1 = 1;
        }
        if (res1 < 0) res1 = 0;
      }
  for (int(i) = 0; (i) < n; i++) {
    for (int(j) = 0; (j) < n; j++) printf("%c", (char)(dp[i][j][0][0] + 'A'));
    puts("");
  }
  return 0;
}
