#include <bits/stdc++.h>
using namespace std;
long long P1 = 31, P2 = 100000014607;
long long P[100005][19], ze[100005], in[100005], out[100005], timer,
    lvl[100005], B[100005], n, m, u[100005], vv[100005];
long long ha[100005], inv[100005], val[100005], rval[100005], num[100005],
    ans[100005];
vector<long long> q[100005];
vector<pair<long long, long long> > v[100005], ever, ver;
vector<pair<pair<long long, long long>, pair<long long, long long> > > g;
long long mul(long long a, long long b) {
  long long m = (long long)((long double)(a)*b / P2);
  long long rem = a * b - m * P2;
  while (rem < 0) rem += P2;
  while (rem >= P2) rem -= P2;
  return rem;
}
long long pw(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = mul(ret, x);
    x = mul(x, x);
    y /= 2;
  }
  return (long long)ret;
}
void go(long long x, long long par, long long la) {
  P[x][0] = par;
  timer++;
  ze[x] = la;
  in[x] = timer;
  if (x > 1) ha[x] = (ha[par] + la * pw(P1, lvl[x] - 2)) % P2;
  for (int i = 1; i <= 17; i++) P[x][i] = P[P[x][i - 1]][i - 1];
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i].first == par) continue;
    lvl[v[x][i].first] = lvl[x] + 1;
    go(v[x][i].first, x, v[x][i].second);
  }
  out[x] = timer;
}
int lca(int a, int b) {
  if (lvl[a] > lvl[b]) swap(a, b);
  if (in[a] <= in[b] && out[b] <= out[a]) return a;
  for (int i = 18; i >= 0; i--)
    if (P[a][i])
      if (!(in[P[a][i]] <= in[b] && out[b] <= out[P[a][i]])) a = P[a][i];
  return P[a][0];
}
long long getpar(long long x, long long dep) {
  for (int i = 17; i >= 0; i--)
    if (lvl[P[x][i]] >= dep) x = P[x][i];
  return x;
}
long long calchash(string x) {
  long long ret = 0;
  for (int i = 0; i < x.size(); i++) ret = (ret * P1 + x[i] - 'a' + 1) % P2;
  return ret;
}
void upd(long long x, long long y) {
  while (x <= 100002) {
    B[x] += y;
    x += x & -x;
  }
}
long long get(long long y) {
  long long x = 0;
  while (y > 0) {
    x += B[y];
    y -= y & -y;
  }
  return x;
}
void add(long long x, long long y, long long z) {
  upd(x, z);
  upd(y + 1, -z);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    long long x, y, z;
    char cc;
    cin >> x >> y >> cc;
    z = cc - 'a' + 1;
    v[x].push_back(make_pair(y, z));
    v[y].push_back(make_pair(x, z));
  }
  lvl[1] = 1;
  go(1, 0, 0);
  for (int i = 1; i <= n; i++) v[i].clear();
  long long cur = P1;
  inv[0] = 1;
  for (int i = 1; i <= n; i++) {
    inv[i] = pw(cur, P2 - 2);
    cur = cur * P1 % P2;
  }
  cin >> m;
  string second;
  for (int i = 1; i <= m; i++) {
    cin >> u[i] >> vv[i] >> second;
    val[i] = calchash(second);
    reverse(second.begin(), second.end());
    rval[i] = calchash(second);
    q[(int)second.size()].push_back(i);
    swap(val[i], rval[i]);
    long long pa = lca(u[i], vv[i]);
    reverse(second.begin(), second.end());
    long long H1 = 0, H2 = 0;
    for (int j = (int)second.size() - 1; j >= 0; j--)
      H2 = (H2 * P1 + second[j] - 'a' + 1) % P2;
    for (int j = 0; j < (int)second.size() - 1; j++) {
      H1 = (H1 * P1 + second[j] - 'a' + 1) % P2;
      H2 = mul((H2 - (second[j] - 'a' + 1)), inv[1]);
      if (H2 < 0) H2 += P2;
      long long x = getpar(u[i], lvl[pa] + j + 1);
      long long y = getpar(vv[i], lvl[pa] + ((int)second.size() - 1 - j));
      long long h = mul((ha[x] - ha[pa]), inv[lvl[pa] - 1]);
      if (h < 0) h += P2;
      if (h != H1) continue;
      h = mul((ha[y] - ha[pa]), inv[lvl[pa] - 1]);
      if (h < 0) h += P2;
      if (h != H2) continue;
      ans[i]++;
    }
  }
  long long ind, pa, pa1;
  for (int l = 1; l <= 100; l++) {
    if ((int)q[l].size() == 0) continue;
    ver.clear();
    for (int i = 1; i <= n; i++) {
      pa = getpar(i, lvl[i] - l);
      if (lvl[i] > l) {
        num[i] = mul((ha[i] - ha[pa]), inv[lvl[pa] - 1]);
        if (num[i] < 0) num[i] += P2;
      } else
        num[i] = -1;
      ver.push_back(make_pair(num[i], i));
    }
    sort(ver.begin(), ver.end());
    g.clear();
    for (int i = 0; i < q[l].size(); i++) {
      ind = q[l][i];
      pa = lca(u[ind], vv[ind]);
      if (lvl[u[ind]] - lvl[pa] >= l) {
        pa1 = getpar(u[ind], lvl[pa] + l - 1);
        g.push_back(
            make_pair(make_pair(rval[ind], ind), make_pair(u[ind], pa1)));
      }
      if (lvl[vv[ind]] - lvl[pa] >= l) {
        pa1 = getpar(vv[ind], lvl[pa] + l - 1);
        g.push_back(
            make_pair(make_pair(val[ind], ind), make_pair(vv[ind], pa1)));
      }
    }
    sort(g.begin(), g.end());
    long long cur = 0;
    for (int i = 0; i < g.size(); i++) {
      if (!i || g[i].first.first != g[i - 1].first.first) {
        for (int j = 0; j < ever.size(); j++)
          add(ever[j].first, ever[j].second, -1);
        ever.clear();
        while (cur < (int)ver.size() && ver[cur].first <= g[i].first.first) {
          if (ver[cur].first == g[i].first.first) {
            add(in[ver[cur].second], out[ver[cur].second], 1);
            ever.push_back(
                make_pair(in[ver[cur].second], out[ver[cur].second]));
          }
          cur++;
        }
      }
      ans[g[i].first.second] +=
          get(in[g[i].second.first]) - get(in[g[i].second.second]);
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
