#include <bits/stdc++.h>
using namespace std;
bool isWinState(map<tuple<char, int, int>, bool> &s1, int first, int sec,
                char prev, vector<vector<pair<int, char>>> &adjList) {
  tuple<char, int, int> t1(prev, first, sec);
  if (s1.find(t1) == s1.end()) {
    for (int i = 0; i < adjList[first].size(); i++) {
      int u = adjList[first][i].first;
      char prevU = adjList[first][i].second;
      if (prevU >= prev && !isWinState(s1, sec, u, prevU, adjList))
        return (s1[t1] = 1);
    }
    return (s1[t1] = 0);
  } else
    return s1[t1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m, u, v;
  char prev;
  cin >> n >> m;
  vector<vector<pair<int, char>>> adjList(n + 1);
  char inEdge[n + 1];
  memset(inEdge, '-', sizeof(inEdge));
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> prev;
    adjList[u].push_back(make_pair(v, prev));
    inEdge[v] = min(inEdge[v], prev);
  }
  vector<int> source;
  for (int i = 1; i <= n; i++) {
    if (inEdge[i] == '-') source.push_back(i);
  }
  map<tuple<char, int, int>, bool> s1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (isWinState(s1, i, j, inEdge[i], adjList))
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
