#include <bits/stdc++.h>
using namespace std;
const int DIM = 2e4 + 5;
vector<pair<int, int>> edg[DIM];
int ord[DIM], fth[DIM], sgn[DIM], val[DIM];
int lst[DIM], alst[DIM], lev[DIM], dep[DIM];
void dfs(int x, int f, int &nr) {
  ord[++nr] = x;
  dep[x] = dep[f] + 1;
  for (pair<int, char> y : edg[x]) {
    if (y.first == f) continue;
    fth[y.first] = x;
    val[y.first] = y.second;
    dfs(y.first, x, nr);
  }
  return;
}
int main(void) {
  ios ::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i < n; ++i) {
    int x, y;
    char c;
    scanf("%d %d %c", &x, &y, &c);
    edg[x].push_back(make_pair(y, c - 'a'));
    edg[y].push_back(make_pair(x, c - 'a'));
  }
  int nr = 0;
  dfs(1, 0, nr);
  while (q--) {
    int x, y, cnt = 0, acnt = 0, ans = 0;
    scanf("%d %d", &x, &y);
    for (int _x = x, _y = y; _x != _y;) {
      if (dep[_x] > dep[_y])
        lst[++cnt] = val[_x], _x = fth[_x];
      else
        alst[++acnt] = val[_y], _y = fth[_y];
    }
    while (acnt) lst[++cnt] = alst[acnt--];
    memset(lev, -1, (n + 1) << 2);
    lev[x] = lev[0] = 0;
    sgn[x] = 1;
    for (int _x = x; _x != 1; _x = fth[_x]) {
      int f = fth[_x];
      lev[f] = lev[_x] + 1;
      if (sgn[_x] == 1)
        sgn[f] = (lev[f] > cnt or val[_x] > lst[lev[f]])
                     ? 2
                     : (val[_x] == lst[lev[f]]);
      else
        sgn[f] = sgn[_x];
    }
    for (int i = 1; i <= n; ++i) {
      int f = ord[i], _x = fth[f];
      if (lev[f] == -1) {
        lev[f] = lev[_x] + 1;
        if (sgn[_x] == 1)
          sgn[f] = (lev[f] > cnt or val[f] > lst[lev[f]])
                       ? 2
                       : (val[f] == lst[lev[f]]);
        else
          sgn[f] = sgn[_x];
      }
      if (!sgn[f] or (sgn[f] == 1 and lev[f] < cnt)) ++ans;
    }
    printf("%d\n", ans - 1);
  }
  return 0;
}
