#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
const int _ = 100007, __ = _ << 1, P = 100, _P = P + 3, lglg = 18;
const unsigned long long bas = 1145141;
int to[__], ne[__], ev[__], he[_] = {0}, ecnt = 1;
inline void adde(int a, int b, int c) {
  to[++ecnt] = b, ev[ecnt] = c, ne[ecnt] = he[a], he[a] = ecnt;
}
inline void addde(int a, int b, int c) { adde(a, b, c), adde(b, a, c); }
int n, fa[_] = {0}, dep[_] = {0}, pfa[_][lglg + 1] = {0};
unsigned long long val[_][_P] = {0};
void dfs(int x, int ff) {
  fa[x] = ff, dep[x] = dep[ff] + 1, pfa[x][0] = fa[x];
  for (int i = 2, j = ff; i <= P; i++, j = fa[j])
    val[x][i] = val[x][i - 1] * bas + val[j][1];
  for (int i = 1; i <= lglg; i++) pfa[x][i] = pfa[pfa[x][i - 1]][i - 1];
  for (int i = he[x]; i; i = ne[i]) {
    int b = to[i];
    if (b == ff) continue;
    val[b][1] = ev[i], dfs(b, x);
  }
}
int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  for (int i = lglg; i >= 0; i--)
    if (dep[pfa[a][i]] >= dep[b]) a = pfa[a][i];
  if (a == b) return a;
  for (int i = lglg; i >= 0; i--)
    if (pfa[a][i] != pfa[b][i]) a = pfa[a][i], b = pfa[b][i];
  return fa[a];
}
int jmp(int a, int d) {
  for (int i = lglg; i >= 0; i--)
    if ((d >> i) & 1) a = pfa[a][i];
  return a;
}
struct jt {
  static const int _t = _ * 70;
  int lc[_t], rc[_t], t[_t], tcnt;
  int alloc(int fr = 0) {
    int x = ++tcnt;
    lc[x] = lc[fr], rc[x] = rc[fr], t[x] = t[fr];
    return x;
  }
  void change(int &x, int y, int l, int r, int tar) {
    x = alloc(y), t[x]++;
    if (l == r) return;
    if (tar <= ((l + r) >> 1))
      change(lc[x], lc[y], l, ((l + r) >> 1), tar);
    else
      change(rc[x], rc[y], ((l + r) >> 1) + 1, r, tar);
  }
  int finder(int x, int y, int l, int r, int tar) {
    if (l == r) return t[x] - t[y];
    if (tar <= ((l + r) >> 1))
      return finder(lc[x], lc[y], l, ((l + r) >> 1), tar);
    return finder(rc[x], rc[y], ((l + r) >> 1) + 1, r, tar);
  }
  jt() {
    memset(lc, 0, sizeof(lc));
    memset(rc, 0, sizeof(rc));
    memset(t, 0, sizeof(t));
    tcnt = 0;
  }
} t;
int rt[_] = {0};
struct cxk {
  int id, a, b;
  string s;
  cxk(int id_ = 0, int a_ = 0, int b_ = 0, string s_ = "") {
    id = id_, a = a_, b = b_, s = s_;
  }
};
vector<cxk> dlq[_P];
int m;
unsigned long long ha[_] = {0};
int lha = 0;
int hashie(unsigned long long x) {
  return lower_bound(ha + 1, ha + lha + 1, x) - ha;
}
int hloc[_] = {0};
void dfsplant(int x) {
  t.change(rt[x], rt[fa[x]], 1, lha, hloc[x]);
  for (int i = he[x]; i; i = ne[i])
    if (to[i] != fa[x]) dfsplant(to[i]);
}
int ans[_] = {0};
unsigned long long hs[_] = {0}, rhs[_] = {0};
int finder(int a, int b, string s) {
  int ans = 0, c = lca(a, b), len = s.size();
  for (int i = 1; i <= len; i++) hs[i] = hs[i - 1] * bas + s[i - 1];
  for (int i = 1; i <= len; i++) rhs[i] = rhs[i - 1] * bas + s[len - i];
  if (dep[a] - dep[c] >= len) {
    int loc = hashie(hs[len]);
    if (loc <= lha && ha[loc] == hs[len])
      ans +=
          t.finder(rt[a], rt[jmp(a, dep[a] - dep[c] - len + 1)], 1, lha, loc);
  }
  if (dep[b] - dep[c] >= len) {
    int loc = hashie(rhs[len]);
    if (loc <= lha && ha[loc] == rhs[len])
      ans +=
          t.finder(rt[b], rt[jmp(b, dep[b] - dep[c] - len + 1)], 1, lha, loc);
  }
  for (int i = jmp(a, max(0, dep[a] - dep[c] - len + 1)); i != c; i = fa[i]) {
    int temp = dep[b] - dep[c] - len + dep[i] - dep[c];
    if (temp < 0) continue;
    int j = jmp(b, temp);
    if (val[i][dep[i] - dep[c]] == hs[dep[i] - dep[c]] &&
        val[j][dep[j] - dep[c]] == rhs[dep[j] - dep[c]])
      ans++;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c, addde(a, b, c);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    string s;
    cin >> a >> b >> s, dlq[s.size()].emplace_back(i, a, b, s);
  }
  dfs(1, 0);
  for (int now = 1; now <= P; now++) {
    if (dlq[now].empty()) continue;
    lha = 0;
    for (int i = 1; i <= n; i++) ha[++lha] = val[i][now];
    sort(ha + 1, ha + lha + 1), lha = unique(ha + 1, ha + lha + 1) - ha - 1;
    for (int i = 1; i <= n; i++) hloc[i] = hashie(val[i][now]);
    t.tcnt = 0, dfsplant(1);
    for (auto i : dlq[now]) ans[i.id] = finder(i.a, i.b, i.s);
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << lf;
  return 0;
}
