#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > G[110];
bool ok[110][110][26];
bool vis[110][110][26];
void solve(int x, int y, int cur) {
  if (vis[x][y][cur]) return;
  vis[x][y][cur] = true;
  bool f = true;
  for (int i = 0; i < G[x].size(); i++) {
    if (G[x][i].second < cur) continue;
    solve(y, G[x][i].first, G[x][i].second);
    if (!ok[y][G[x][i].first][G[x][i].second]) {
      f = false;
      break;
    }
  }
  if (!f)
    ok[x][y][cur] = true;
  else
    ok[x][y][cur] = false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    char c;
    scanf("%d%d%c%c", &u, &v, &c, &c);
    G[u].push_back(make_pair(v, c - 'a'));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      solve(i, j, 0);
      if (ok[i][j][0])
        printf("A");
      else
        printf("B");
    }
    puts("");
  }
  return 0;
}
