#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
template <typename T>
inline T BigMod(T A, T B) {
  T ret = 1;
  while (B) {
    if (B & 1) ret = (ret * A) % 1000000007;
    A = (A * A) % 1000000007;
    B = B >> 1;
  }
  return ret;
}
template <typename T>
inline T InvMod(T A, T M = 1000000007) {
  return BigMod(A, M - 2);
}
string tostring(long long int res) {
  string curstr = "";
  while (res != 0) {
    long long int temp = (res % 10);
    curstr += ((char)temp + '0');
    res /= 10;
  }
  reverse(curstr.begin(), curstr.end());
  return curstr;
}
long long int toint(string ss) {
  long long int inss = 0;
  for (int i = 0; i < ss.size(); i++) {
    inss = (inss * 10) + ((int)(ss[i] - '0'));
  }
  return inss;
}
int dp[2][105][105][29], vis[105][105];
vector<pair<int, char> > graph[105];
int call(int cur, int node, int node2, int val) {
  if (dp[cur][node][node2][val] != -1) return dp[cur][node][node2][val];
  int ans = 0;
  if (!cur) {
    for (int i = 0; i < graph[node].size(); i++) {
      int vv = graph[node][i].first;
      int ch = ((graph[node][i].second - 'a')) + 1;
      if (ch < val) continue;
      ans |= call(1 - cur, vv, node2, ch);
    }
  } else {
    ans = 1;
    for (int i = 0; i < graph[node2].size(); i++) {
      int vv = graph[node2][i].first;
      int ch = ((graph[node2][i].second - 'a')) + 1;
      if (ch < val) continue;
      ans &= call(1 - cur, node, vv, ch);
    }
  }
  return dp[cur][node][node2][val] = ans;
}
int main() {
  int n, m, x, u, v, tc;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < 105; i++) graph[i].clear();
  for (int i = 0; i < m; i++) {
    char ch;
    scanf("%d %d", &u, &v);
    cin >> ch;
    graph[u].push_back(make_pair(v, ch));
  }
  memset(dp, -1, sizeof(dp));
  for (int x = 1; x <= n; x++) {
    for (int j = 1; j <= n; j++) {
      int ans = call(0, x, j, 0);
      if (ans == 1) {
        vis[x][j] = 1;
      }
    }
  }
  string str[105];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (vis[i][j])
        str[i] += 'A';
      else
        str[i] += 'B';
    }
  }
  for (int i = 1; i <= n; i++) cout << str[i] << endl;
  return 0;
}
