#include <bits/stdc++.h>
using namespace std;
class TaskD {
 private:
  int dfs(int a, int b, int c, const vector<vector<pair<int, int>>>& g,
          vector<vector<vector<int>>>& dp) {
    if (dp[a][b][c] != -1) {
      return dp[a][b][c];
    }
    for (const auto& p : g[a]) {
      if (p.second >= c && !dfs(b, p.first, p.second, g, dp)) {
        return (dp[a][b][c] = 1);
      }
    }
    return (dp[a][b][c] = 0);
  }

 public:
  void solve(istream& in, ostream& out) {
    int n, m;
    in >> n >> m;
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; ++i) {
      int v, u;
      char c;
      in >> v >> u >> c;
      g[v - 1].emplace_back(u - 1, c - 'a');
    }
    vector<vector<vector<int>>> dp(n,
                                   vector<vector<int>>(n, vector<int>(26, -1)));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (dfs(i, j, 0, g, dp)) {
          out << 'A';
        } else {
          out << 'B';
        }
      }
      out << '\n';
    }
  }
};
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  TaskD solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
