#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e4 + 1;
int n, q, u, v, x, y, res;
int dep[MAX], par[MAX], pool, above[MAX], pos[MAX], inv_pos[MAX];
int n_s, n_inv_s, len[MAX], cmp[MAX];
char digit[MAX], s[MAX], inv_s[MAX];
vector<pair<int, int> > adj[MAX];
void visit(const int& u = 1) {
  pos[++pool] = u;
  inv_pos[u] = pool;
  above[pool] = inv_pos[par[u]];
  for (pair<int, int>& v : adj[u])
    if (v.first != par[u]) {
      digit[v.first] = v.second;
      dep[v.first] = dep[u] + 1;
      par[v.first] = u;
      visit(v.first);
    }
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i < n; ++i) {
    scanf("%d %d %s", &u, &v, s);
    adj[u].push_back(pair<int, int>(v, s[0]));
    adj[v].push_back(pair<int, int>(u, s[0]));
  }
  visit();
  while (q--) {
    scanf("%d %d", &u, &v);
    x = u, y = v;
    n_s = n_inv_s = 0;
    memset(s + 1, 0, n * sizeof(char));
    while (x != y) {
      if (dep[x] > dep[y]) {
        s[++n_s] = digit[x];
        x = par[x];
      } else {
        inv_s[++n_inv_s] = digit[y];
        y = par[y];
      }
    }
    for (int i = n_inv_s; i > 0; --i) s[++n_s] = inv_s[i];
    memset(len + 1, -1, n * sizeof(int));
    x = inv_pos[u], cmp[x] = len[x] = res = 0;
    while (above[x]) {
      len[above[x]] = len[x] + 1;
      if (cmp[x] != 0)
        cmp[above[x]] = cmp[x];
      else
        cmp[above[x]] = (digit[pos[x]] > s[len[above[x]]]) -
                        (digit[pos[x]] < s[len[above[x]]]);
      x = above[x];
      if (cmp[x] == -1 || (cmp[x] == 0 && len[x] < n_s)) ++res;
    }
    for (int x = 1; x <= n; ++x)
      if (len[x] == -1) {
        len[x] = len[above[x]] + 1;
        if (cmp[above[x]] != 0)
          cmp[x] = cmp[above[x]];
        else
          cmp[x] = (digit[pos[x]] > s[len[x]]) - (digit[pos[x]] < s[len[x]]);
        if (cmp[x] == -1 || (cmp[x] == 0 && len[x] < n_s)) ++res;
      }
    printf("%d\n", res);
  }
  return 0;
}
