#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > solve[30];
unordered_map<int, unordered_map<int, char> > mtr;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= 1000000; p++) {
    if (prime[p] == true) {
      for (long long nd = p * 2; nd <= 1000000; nd += p) prime[nd] = false;
    }
  }
}
int gcd(int val1, int val2) {
  if (val1 == 0)
    return val2;
  else
    return gcd(val2 % val1, val1);
}
char eval(int findo, int loc2, int crm) {
  if (solve[crm][findo][loc2] != -1) {
    return solve[crm][findo][loc2];
  }
  solve[crm][findo][loc2] = 1;
  for (auto &ind : mtr[findo]) {
    int answer = ind.second - 'a';
    if (answer < crm) continue;
    solve[crm][findo][loc2] =
        min(solve[crm][findo][loc2], 1 - eval(loc2, ind.first, answer));
    if (solve[crm][findo][loc2] == 0) break;
  }
  return solve[crm][findo][loc2];
}
struct vect {
  struct vect *foll;
  long long answer;
  struct vect *succ;
};
void upd(struct vect **beg, struct vect **end, long long xd) {
  struct vect *c = (struct vect *)malloc(sizeof(struct vect));
  c->answer = xd;
  c->succ = NULL;
  if (*beg == NULL) {
    c->foll = NULL;
    *beg = c;
    *end = c;
    return;
  }
  (*end)->succ = c;
  c->foll = *end;
  *end = c;
}
void change(struct vect **beg, struct vect **end) {
  if (*beg == *end) {
    return;
  }
  (*end)->succ = *beg;
  (*beg)->foll = *end;
  *beg = *end;
  *end = (*end)->foll;
  (*end)->succ = NULL;
  (*beg)->foll = NULL;
}
int main() {
  int inp;
  int col;
  int val1;
  int val2;
  scanf("%d", &inp);
  scanf("%d", &col);
  for (int ind = 0; ind <= 26; ind++)
    solve[ind].assign(inp + 1, vector<int>(inp + 1, -1));
  for (int ind = 1; ind <= col; ind++) {
    scanf("%d", &val1);
    scanf("%d", &val2);
    val1--;
    val2--;
    cin >> mtr[val1][val2];
  }
  for (int ind = 0; ind < inp; ind++) {
    for (int rt = 0; rt < inp; rt++) {
      if (eval(ind, rt, 0) == 1) {
        cout << 'B';
      } else
        cout << 'A';
    }
    cout << endl;
  }
}
