#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
int addm(int& a, int b) { return (a += b) < mod ? a : a -= mod; }
template <class T, class U>
bool smin(T& a, U b) {
  return a > b ? (a = b, 1) : 0;
}
template <class T, class U>
bool smax(T& a, U b) {
  return a < b ? (a = b, 1) : 0;
}
int n, q, ct, len, first, second, ans, ord[20000], p[20000], l[20000],
    comp[20000], loc[20000];
char s[20000], t[20000], lab[20000];
vector<pair<int, int> > al[20000];
void dfs(int i, int pa = -1, int lo = -1) {
  p[ct] = lo;
  ord[lo = ct++] = i;
  loc[i] = lo;
  for (pair<int, int>& j : al[i])
    if (j.first != pa) {
      dfs(j.first, i, lo);
      lab[loc[j.first]] = j.second;
    }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    u--;
    v--;
    al[u].push_back({v, c});
    al[v].push_back({u, c});
  }
  dfs(0);
  for (int i = 0; i < n; i++) assert(p[i] < i);
  for (int i = 0; i < q; i++) {
    cin >> first >> second;
    first--;
    second--;
    first = loc[first];
    second = loc[second];
    int u = first, v = second;
    int ls = 0, lt = 0;
    for (; u != v;) {
      if (u > v)
        s[ls++] = lab[u], u = p[u];
      else
        t[lt++] = lab[v], v = p[v];
    }
    for (; lt;) s[ls++] = t[--lt];
    u = first;
    fill(l, l + n, -1);
    l[u] = 0;
    comp[u] = 0;
    ans = 0;
    for (; p[u] != -1; u = p[u]) {
      l[p[u]] = l[u] + 1;
      if (comp[u] == 0) {
        if (l[u] < ls)
          comp[p[u]] = (s[l[u]] < lab[u]) - (s[l[u]] > lab[u]);
        else
          comp[p[u]] = 0;
      } else
        comp[p[u]] = comp[u];
      if (comp[p[u]] == -1 || (comp[p[u]] == 0 && l[p[u]] < ls)) ans++;
    }
    for (int i = 0; i < n; i++)
      if (l[i] == -1) {
        if (p[i] == -1) cerr << i << endl;
        l[i] = l[p[i]] + 1;
        if (comp[p[i]] == 0) {
          if (l[i] <= ls)
            comp[i] = (s[l[i] - 1] < lab[i]) - (s[l[i] - 1] > lab[i]);
          else
            comp[i] = 0;
        } else
          comp[i] = comp[p[i]];
        if (comp[i] == -1 || (comp[i] == 0 && l[i] < ls)) ans++;
      }
    cout << ans << '\n';
  }
}
