#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T, class U>
inline void print(T first, U second) {
  printsp(first);
  println(second);
}
template <class T, class U, class V>
inline void print(T first, U second, V z) {
  printsp(first);
  printsp(second);
  println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
vector<int> adj[20020];
vector<char> ch[20020];
vector<pair<int, int> > qu[20020];
int sz[20020], dep[20020];
string s;
int ans[20020], fa[20020];
char fc[20020];
void dfs(int u, int pa = 0) {
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (pa == v) continue;
    fc[v] = ch[u][i];
    fa[v] = u;
    dfs(v, u);
    sz[u] += sz[v];
  }
}
int flag, vst[20020];
int calc(int u, int v) {
  ++flag;
  s.clear();
  static int q[20020], qb, d[20020];
  qb = 0;
  while (u != v) {
    s += fc[v];
    v = fa[v];
    q[qb++] = v;
    vst[v] = flag;
  }
  reverse(s.begin(), s.end());
  reverse(q, q + qb);
  for (int i = 0; i < qb; i++) d[i] = i;
  int res = qb - 1;
  for (int i = 0; i < qb; i++) {
    int cur = q[i], dep = d[i];
    for (int j = 0; j < adj[cur].size(); j++) {
      v = adj[cur][j];
      if (vst[v] == flag) continue;
      if (ch[cur][j] < s[dep]) {
        res += sz[v];
      }
      if (ch[cur][j] == s[dep]) {
        if (dep + 1 < s.size()) {
          res++;
          q[qb] = v;
          d[qb++] = dep + 1;
          vst[v] = flag;
        }
      }
    }
  }
  return res;
}
int n;
void solve(int u, int pa = 0) {
  for (int i = 0; i < qu[u].size(); i++) {
    ans[qu[u][i].second] = calc(u, qu[u][i].first);
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == pa) continue;
    fa[u] = v;
    fa[v] = 0;
    fc[u] = ch[u][i];
    fc[v] = 0;
    sz[u] = n - sz[v];
    sz[v] = n;
    solve(v, u);
    fa[v] = u;
    fa[u] = 0;
    fc[v] = ch[u][i];
    fc[u] = 0;
    sz[v] = n - sz[u];
    sz[u] = n;
  }
}
int main() {
  int q;
  gn(n, q);
  for (int i = 1; i < n; i++) {
    int u, v;
    char c;
    gn(u, v);
    c = getchar();
    adj[u].push_back(v);
    adj[v].push_back(u);
    ch[u].push_back(c);
    ch[v].push_back(c);
  }
  dfs(1);
  for (int i = 1; i <= q; i++) {
    int u, v;
    gn(u, v);
    qu[u].push_back(pair<int, int>(v, i));
  }
  solve(1);
  for (int i = 1; i <= q; i++) println(ans[i]);
  return 0;
}
