#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20001;
vector<pair<int, char> > g[MAXN];
int fa[MAXN];
char efa[MAXN];
char s0[MAXN], s1[MAXN];
int m0, m1, stn;
int dep[MAXN], pos[MAXN], comp[MAXN], sta[MAXN];
int ans;
int sgn(int x) {
  if (x > 0)
    return 1;
  else if (x < 0)
    return -1;
  else
    return 0;
}
void DFS0(int u, int pre) {
  dep[u] = dep[pre] + 1;
  for (auto &p : g[u])
    if (p.first != pre) {
      fa[p.first] = u;
      efa[p.first] = p.second;
      DFS0(p.first, u);
    }
  return;
}
int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);
  for (int i = 1; i < n; ++i) {
    int u, v;
    char st[5];
    scanf("%d%d%s", &u, &v, st);
    g[u].push_back(make_pair(v, st[0]));
    g[v].push_back(make_pair(u, st[0]));
  }
  DFS0(1, 0);
  while (qn--) {
    int u, v, x, y;
    scanf("%d%d", &x, &y);
    u = x;
    v = y;
    m0 = m1 = 0;
    while (dep[u] > dep[v]) s0[m0++] = efa[u], u = fa[u];
    while (dep[v] > dep[u]) s1[m1++] = efa[v], v = fa[v];
    while (u != v) s0[m0++] = efa[u], u = fa[u], s1[m1++] = efa[v], v = fa[v];
    while (m1--) s0[m0++] = s1[m1];
    memset(pos, -1, sizeof(pos));
    memset(comp, 0, sizeof(comp));
    pos[x] = 0;
    ans = 0;
    for (u = x; fa[u] != 0; u = fa[u]) {
      pos[fa[u]] = pos[u] + 1;
      if (comp[u] == 0) {
        if (pos[u] < m0)
          comp[fa[u]] = sgn(efa[u] - s0[pos[u]]);
        else
          comp[fa[u]] = 1;
      } else
        comp[fa[u]] = comp[u];
      if (comp[fa[u]] < 0 || comp[fa[u]] == 0 && pos[fa[u]] < m0) ans++;
    }
    for (int i = 1; i <= n; ++i)
      if (pos[i] == -1) {
        for (stn = 0, u = i; pos[u] == -1; u = fa[u]) sta[stn++] = u;
        while (stn > 0) {
          v = sta[--stn];
          pos[v] = pos[u] + 1;
          if (comp[u] == 0) {
            if (pos[u] < m0)
              comp[v] = sgn(efa[v] - s0[pos[u]]);
            else
              comp[v] = 1;
          } else
            comp[v] = comp[u];
          if (comp[v] < 0 || comp[v] == 0 && pos[v] < m0) ans++;
          u = v;
        }
      }
    printf("%d\n", ans);
  }
  return 0;
}
