#include <bits/stdc++.h>
using namespace std;
unsigned long long pw[201000], _pw[201000];
struct Data {
  int len, id;
  unsigned long long h;
};
struct hash_table {
  int head[11009990], nxt[10100000], p[10100000], ptr;
  unsigned long long d[10100000];
  void add(unsigned long long x, int a) {
    int z = x % 11009989;
    for (int t = head[z]; t; t = nxt[t])
      if (d[t] == x) {
        p[t] += a;
        return;
      }
    nxt[++ptr] = head[z], head[z] = ptr;
    p[ptr] += a, d[ptr] = x;
  }
  int find(unsigned long long x) {
    int z = x % 11009989;
    for (int t = head[z]; t; t = nxt[t])
      if (d[t] == x) return p[t];
    return 0;
  }
} st;
int anses[201000], prec[201000], dep[201000], fa[21][201000], n, m;
vector<pair<int, int> > G[201000];
vector<Data> Q[201000];
void dfs(int u, int f) {
  fa[0][u] = f;
  for (auto c : G[u])
    if (c.first != f) {
      dep[c.first] = dep[u] + 1;
      pw[c.first] = pw[u] * (19260817) + (c.second);
      prec[c.first] = c.second;
      dfs(c.first, u);
    }
}
unsigned long long get(int l, int r) {
  return pw[l] - pw[r] * _pw[dep[l] - dep[r]];
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  for (int i = 0; d >> i; i++)
    if (d >> i & 1) u = fa[i][u];
  if (u == v) return u;
  for (int i = 19; i >= 0; --i)
    if (fa[i][u] ^ fa[i][v]) u = fa[i][u], v = fa[i][v];
  return fa[0][u];
}
int jmp(int u, int d) {
  for (int i = 0; d >> i; i++)
    if (d >> i & 1) u = fa[i][u];
  return u;
}
unsigned long long geth(char* s) {
  unsigned long long ret = 0;
  for (int i = 0; s[i]; i++) ret = ret * (19260817) + (s[i]);
  return ret;
}
int kmp(char* t, char* s) {
  static int f[201000];
  int n = max(strlen(s), strlen(t)), ns = strlen(s);
  for (int i = 0; i < n; ++i) f[i] = 0;
  f[0] = -1;
  for (int i = 1; s[i]; i++) {
    int j = f[i - 1];
    while (j != -1 && s[j + 1] != s[i]) j = f[j];
    if (s[j + 1] == s[i]) j++;
    f[i] = j;
  }
  int ans = 0;
  for (int i = 0, x = -1; t[i]; i++) {
    while (x != -1 && s[x + 1] != t[i]) x = f[x];
    if (s[x + 1] == t[i]) x++;
    if (x == ns - 1) ans++;
  }
  return ans;
}
void dfs2(int u, int f) {
  for (int i = 1, x = f; i <= 100 && x; i++) {
    st.add(get(u, x), 1);
    x = fa[0][x];
  }
  for (auto c : Q[u]) anses[abs(c.id)] += (c.id > 0 ? 1 : -1) * st.find(c.h);
  for (auto c : G[u])
    if (c.first != f) dfs2(c.first, u);
  for (int i = 1, x = f; i <= 100 && x; i++)
    st.add(get(u, x), -1), x = fa[0][x];
}
int main() {
  scanf("%d", &n);
  _pw[0] = (1);
  for (int i = 1; i <= n; ++i) _pw[i] = _pw[i - 1] * (19260817);
  for (int i = 2, u, v; i <= n; ++i) {
    char s[2];
    scanf("%d%d%s", &u, &v, s);
    G[u].push_back(pair<int, int>(v, s[0]));
    G[v].push_back(pair<int, int>(u, s[0]));
  }
  dfs(1, 0);
  for (int i = 1; i < 20; ++i)
    for (int j = 1; j <= n; ++j) fa[i][j] = fa[i - 1][fa[i - 1][j]];
  scanf("%d", &m);
  for (int i = 1, u, v; i <= m; ++i) {
    char s[200], t[300];
    int tp = 0;
    scanf("%d%d%s", &u, &v, s);
    int lc = lca(u, v), len = strlen(s);
    int zu = jmp(u, max(0, dep[u] - dep[lc] - len));
    int zv = jmp(v, max(0, dep[v] - dep[lc] - len));
    Q[zv].push_back(Data{len, -i, geth(s)});
    Q[v].push_back(Data{len, i, geth(s)});
    reverse(s, s + len);
    Q[zu].push_back(Data{len, -i, geth(s)});
    Q[u].push_back(Data{len, i, geth(s)});
    reverse(s, s + len);
    while (zu != lc) t[tp++] = prec[zu], zu = fa[0][zu];
    int xp = tp;
    while (zv != lc) t[tp++] = prec[zv], zv = fa[0][zv];
    reverse(t + xp, t + tp);
    t[tp] = 0;
    anses[i] = kmp(t, s);
  }
  dfs2(1, 0);
  for (int i = 1; i <= m; ++i) printf("%d\n", anses[i]);
}
