#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LINF = 2e16;
const int INF = 2e9;
const int magic = 348;
const double eps = 1e-10;
const double pi = 3.14159265;
inline int getint() {
  char ch;
  int res;
  bool f;
  while (!isdigit(ch = getchar()) && ch != '-') {
  }
  if (ch == '-')
    f = false, res = 0;
  else
    f = true, res = ch - '0';
  while (isdigit(ch = getchar())) res = res * 10 + ch - '0';
  return f ? res : -res;
}
int n, q, X, Y, LCA;
vector<pair<int, int> > v[20048];
vector<pair<int, int> > vv[20048];
int depth[20048], fa[20048], faedge[20048];
int sz[20048];
int L[20048], R[20048], pos[20048], anc[20048][21];
int ind = 0;
int Len[20048], sta[20048];
int seq[20048];
inline void dfs(int cur, int father) {
  int i, j, second;
  sz[cur] = 1;
  L[cur] = ++ind;
  pos[cur] = ind;
  seq[ind] = cur;
  for (i = 0; i < int(v[cur].size()); i++) {
    second = v[cur][i].first;
    if (second != father) {
      depth[second] = depth[cur] + 1;
      fa[second] = cur;
      faedge[second] = v[cur][i].second;
      anc[second][0] = cur;
      for (j = 1; j <= 20; j++) anc[second][j] = anc[anc[second][j - 1]][j - 1];
      dfs(second, cur);
      sz[cur] += sz[second];
    }
  }
  R[cur] = ind;
}
inline int getlca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  for (register int i = 20; i >= 0; i--)
    if (depth[anc[u][i]] >= depth[v]) u = anc[u][i];
  if (u == v) return u;
  for (register int i = 20; i >= 0; i--)
    if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];
  return fa[u];
}
int ans = 0;
int List[20048], tmp[20048], tot, ttot;
inline void getlist(int u, int v) {
  tot = ttot = 0;
  while (u != v)
    if (depth[u] > depth[v])
      List[++tot] = faedge[u], u = fa[u];
    else
      tmp[++ttot] = faedge[v], v = fa[v];
  for (register int i = ttot; i >= 1; i--) List[++tot] = tmp[i];
}
inline int calc(int cur, int to) {
  if (fa[to] == cur)
    return sz[to];
  else
    return n - sz[cur];
}
inline int Getedge(int cur, int to, bool isover) {
  if (!isover) return faedge[cur];
  int l = 0, r = int(vv[cur].size()) - 1, mid, second;
  while (l <= r) {
    mid = (l + r) >> 1;
    second = vv[cur][mid].first;
    if (L[second] <= pos[to] && pos[to] <= R[second]) return faedge[second];
    if (pos[to] < L[second])
      r = mid - 1;
    else
      l = mid + 1;
  }
  assert(false);
}
inline int Get(int cur, int to, bool isover) {
  if (!isover) return fa[cur];
  int l = 0, r = int(vv[cur].size()) - 1, mid, second;
  while (l <= r) {
    mid = (l + r) >> 1;
    second = vv[cur][mid].first;
    if (L[second] <= pos[to] && pos[to] <= R[second]) return second;
    if (pos[to] < L[second])
      r = mid - 1;
    else
      l = mid + 1;
  }
  assert(false);
}
int Q[200048], head, tail;
inline void Dfs(int cur, int d, int father, int sta, int qcur) {
  Q[1] = cur;
  Q[2] = d;
  Q[3] = father;
  Q[4] = qcur;
  head = 1;
  tail = 4;
  int i, second, cmp, Cmp, nxt;
  bool isover = false;
  while (head <= tail) {
    cur = Q[head++];
    d = Q[head++];
    father = Q[head++];
    qcur = Q[head++];
    if (qcur == LCA) isover = true;
    if (d >= tot) continue;
    ans++;
    for (i = 0; i < int(v[cur].size()); i++) {
      second = v[cur][i].first;
      if (second == father) continue;
      cmp = v[cur][i].second;
      Cmp = Getedge(qcur, Y, isover);
      if (cmp > Cmp) continue;
      if (cmp < Cmp) {
        ans += calc(cur, second);
        continue;
      }
      nxt = Get(qcur, Y, isover);
      Q[++tail] = second;
      Q[++tail] = d + 1;
      Q[++tail] = cur;
      Q[++tail] = nxt;
    }
  }
}
inline void Dfs(int cur, int d, int father, int sta) {
  Q[1] = cur;
  Q[2] = d;
  Q[3] = father;
  Q[4] = sta;
  head = 1;
  tail = 4;
  int i, second, cmp;
  while (head <= tail) {
    cur = Q[head++];
    d = Q[head++];
    father = Q[head++];
    sta = Q[head++];
    if (sta == 1 || (sta == 0 && d < tot)) ans++;
    if (sta == 0 && d >= tot) continue;
    for (i = 0; i < int(v[cur].size()); i++) {
      second = v[cur][i].first;
      if (second == father) continue;
      if (sta) {
        Q[++tail] = second;
        Q[++tail] = d + 1;
        Q[++tail] = cur;
        Q[++tail] = sta;
        continue;
      }
      cmp = v[cur][i].second;
      if (cmp > List[d + 1]) continue;
      if (cmp < List[d + 1]) {
        ans += calc(cur, second);
        continue;
      }
      Q[++tail] = second;
      Q[++tail] = d + 1;
      Q[++tail] = cur;
      Q[++tail] = 0;
    }
  }
}
int main() {
  int i, j, first, second;
  char c;
  n = getint();
  q = getint();
  for (i = 1; i <= n - 1; i++) {
    cin >> first >> second >> c;
    v[first].push_back(make_pair(second, c));
    v[second].push_back(make_pair(first, c));
  }
  depth[1] = 1;
  dfs(1, -1);
  for (i = 1; i <= n; i++)
    for (j = 0; j < int(v[i].size()); j++)
      if (v[i][j].first != fa[i]) vv[i].push_back(v[i][j]);
  while (q--) {
    first = getint();
    second = getint();
    X = first;
    Y = second;
    ans = 0;
    getlist(first, second);
    memset(Len, -1, sizeof(Len));
    sta[first] = 0;
    Len[first] = 0;
    for (register int cur = first; fa[cur]; cur = fa[cur]) {
      Len[fa[cur]] = Len[cur] + 1;
      if (sta[cur]) {
        sta[fa[cur]] = sta[cur];
        continue;
      }
      if (faedge[cur] == List[Len[fa[cur]]]) {
        if (Len[fa[cur]] == tot)
          sta[fa[cur]] = 1;
        else
          sta[fa[cur]] = 0;
      }
      if (faedge[cur] < List[Len[fa[cur]]]) sta[fa[cur]] = 2;
      if (faedge[cur] > List[Len[fa[cur]]]) sta[fa[cur]] = 1;
    }
    int ans = 0;
    for (i = 1; i <= n; i++) {
      int cur = seq[i];
      if (Len[cur] == -1) {
        Len[cur] = Len[fa[cur]] + 1;
        if (sta[fa[cur]])
          sta[cur] = sta[fa[cur]];
        else {
          if (faedge[cur] == List[Len[cur]]) {
            if (Len[cur] == tot)
              sta[cur] = 1;
            else
              sta[cur] = 0;
          }
          if (faedge[cur] < List[Len[cur]]) sta[cur] = 2;
          if (faedge[cur] > List[Len[cur]]) sta[cur] = 1;
        }
      }
      if (sta[cur] != 1) ans++;
    }
    printf("%d\n", ans - 1);
  }
  return 0;
}
