#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
  a %= m;
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ((ret % m) * (a % m)) % m;
    a = ((a % m) * (a % m)) % m;
    b >>= 1;
  }
  return ret;
}
vector<pair<int, char> > v[101];
int n, m;
int dp[101][101][2][26];
int func(int x, int y, int ch, int player) {
  if (ch != 60) {
    if (dp[x][y][player][ch - 'a'] != -1) return dp[x][y][player][ch - 'a'];
  }
  int sig = 0;
  int flag = 0;
  if (player == 0) {
    for (pair<int, char> p : v[x]) {
      if ((int)p.second >= ch) {
        flag = 1;
        if (func(p.first, y, (int)p.second, 1) == 0) sig = 1;
      }
    }
  } else {
    for (pair<int, char> p : v[y]) {
      if ((int)p.second >= ch) {
        flag = 1;
        if (func(x, p.first, (int)p.second, 0) == 1) sig = 1;
      }
    }
  }
  if (!flag) {
    if (ch != 60) dp[x][y][player][ch - 'a'] = (player ^ 1);
    return (player ^ 1);
  }
  if (sig) {
    if (ch != 60) dp[x][y][player][ch - 'a'] = player;
    return player;
  }
  if (ch != 60) dp[x][y][player][ch - 'a'] = (player ^ 1);
  return (player ^ 1);
}
int main() {
  memset(dp, -1, sizeof(dp));
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    char ch;
    cin >> x >> y >> ch;
    v[x].push_back(make_pair(y, ch));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!func(i, j, 60, 0))
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
