#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > adj[104];
long long dp[102][102][27];
bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) {
  return (p1.second > p2.second);
}
long long func(long long u, long long v, long long val) {
  if (dp[u][v][val] != -1) {
    return dp[u][v][val];
  }
  long long i, j, flag;
  for (j = 0; j < adj[u].size(); ++j) {
    flag = 0;
    if (adj[u][j].second - 'a' < val) {
      flag = 1;
    }
    for (i = 0;
         i < adj[v].size() && adj[v][i].second >= adj[u][j].second && flag == 0;
         ++i) {
      flag =
          flag | func(adj[u][j].first, adj[v][i].first, adj[v][i].second - 'a');
    }
    if (flag == 0) {
      dp[u][v][val] = 0;
      return 0;
    }
  }
  dp[u][v][val] = 1;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long n, m, u, v;
  char ch;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v >> ch;
    --u;
    --v;
    adj[u].push_back(make_pair(v, (long long)ch));
  }
  for (int i = 0; i < n; ++i) {
    sort(adj[i].begin(), adj[i].end(), cmp);
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < 26; ++k) {
        dp[i][j][k] = -1;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      func(i, j, 0);
      cout << (char)('A' + dp[i][j][0]);
    }
    cout << "\n";
  }
  return 0;
}
