#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T>
ostream& prnt(ostream& out, T v) {
  out << v.size() << '\n';
  for (auto e : v) out << e << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T> v) {
  return prnt(out, v);
}
template <class T>
ostream& operator<<(ostream& out, set<T> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, map<T1, T2> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  return out << '(' << p.first << ' ' << p.second << ')';
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
const long double PI = acos(-1);
int n, a, b, height[100005], fth[18][100005], val[100005];
char c;
vector<pair<int, char>> v[100005];
unsigned long long H[100005][105], H2[100005][105], P[100005];
unordered_set<unsigned long long> S;
unordered_map<unsigned long long, int> M, M2;
unordered_map<unsigned long long, int> need[100005], need2[100005];
struct ceva {
  int a, b, sz, ans, p1, p2;
  unsigned long long s;
} q[100005];
void dfs(int nod, int ant = 0, int h = 1) {
  height[nod] = h;
  fth[0][nod] = ant;
  for (auto& [it, c] : v[nod]) {
    if (it == ant) continue;
    val[it] = c;
    for (int j = 1; j <= 100; j++) {
      H[it][j] = H[nod][j - 1] + P[j] * (c - 'a' + 1);
      H2[it][j] = H2[nod][j - 1] * 73 + (c - 'a' + 1);
    }
    dfs(it, nod, h + 1);
  }
}
unsigned long long getHash(string s) {
  unsigned long long h = 0;
  for (auto it : s) h = h * 73 + (it - 'a' + 1);
  return h;
}
void dfs2(int nod, int ant = 0) {
  for (int i = 1; i <= 100; i++) {
    if (S.count(H[nod][i])) M[H[nod][i]]++;
    if (S.count(H2[nod][i])) M2[H2[nod][i]]++;
  }
  for (auto& [it, v] : need[nod]) {
    if (M.count(it)) {
      v = M[it];
    }
  }
  for (auto& [it, v] : need2[nod]) {
    if (M2.count(it)) {
      v = M2[it];
    }
  }
  for (auto& [it, c] : v[nod]) {
    if (it == ant) continue;
    dfs2(it, nod);
  }
  for (int i = 1; i <= 100; i++) {
    if (S.count(H[nod][i])) M[H[nod][i]]--;
    if (S.count(H2[nod][i])) M2[H2[nod][i]]--;
  }
}
int LCA(int a, int b) {
  if (height[a] > height[b]) swap(a, b);
  for (int i = 17; i >= 0; i--)
    if (height[b] - (1 << i) >= height[a]) {
      b = fth[i][b];
    }
  for (int i = 17; i >= 0; i--)
    if (fth[i][b] != fth[i][a]) a = fth[i][a], b = fth[i][b];
  if (a == b) return a;
  return fth[0][a];
}
int goUp(int a, int k) {
  for (int i = 17; i >= 0; i--)
    if (k >= (1 << i)) a = fth[i][a], k -= (1 << i);
  return a;
}
vector<int> prefix(string const& A) {
  vector<int> pr(A.size() + 1, 0);
  int k = 0;
  for (int i = 2; i <= A.size(); i++) {
    while (k && A[k] != A[i - 1]) k = pr[k];
    if (A[k] == A[i - 1]) k++;
    pr[i] = k;
  }
  return pr;
}
int KMP(string const& A, string const& C) {
  vector<int> pr = prefix(C);
  int k = 0, ans = 0;
  for (int i = 1; i <= A.size(); i++) {
    while (k && C[k] != A[i - 1]) k = pr[k];
    if (C[k] == A[i - 1]) k++;
    if (k == C.size()) {
      ans++;
    }
  }
  return ans;
}
int compute(int a, int b, string& tr) {
  int c = LCA(a, b);
  string s, s2;
  while (a != c) {
    s += val[a];
    a = fth[0][a];
  }
  while (b != c) {
    s2 += val[b];
    b = fth[0][b];
  }
  reverse(s2.begin(), s2.end());
  s += s2;
  return KMP(s, tr);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a >> b >> c;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  P[1] = 1;
  for (int i = 2; i <= n; i++) P[i] = P[i - 1] * 73;
  for (int j = 0; j <= n; j++)
    for (int i = 1; i <= 100; i++) H[j][i] = H2[j][i] = 2134214241412LL;
  dfs(1);
  for (int i = 1; i < 18; i++)
    for (int j = 1; j <= n; j++) {
      fth[i][j] = fth[i - 1][fth[i - 1][j]];
    }
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    string s;
    cin >> q[i].a >> q[i].b >> s;
    int a = q[i].a, b = q[i].b;
    q[i].ans = 0;
    q[i].sz = s.size();
    q[i].s = getHash(s);
    S.insert(q[i].s);
    need[a][q[i].s] = 0;
    need2[b][q[i].s] = 0;
    int c = LCA(a, b);
    int x = (height[a] - height[c] - q[i].sz + 1);
    if (x >= 0) {
      q[i].p1 = goUp(a, x);
      need[q[i].p1][q[i].s] = 0;
    } else {
      q[i].p1 = a;
    }
    int x2 = (height[b] - height[c] - q[i].sz + 1);
    if (x2 >= 0) {
      q[i].p2 = goUp(b, x2);
      need2[q[i].p2][q[i].s] = 0;
    } else {
      q[i].p2 = b;
    }
    q[i].ans = compute(q[i].p1, q[i].p2, s);
  }
  dfs2(1);
  for (int i = 1; i <= Q; i++) {
    q[i].ans += need[q[i].a][q[i].s] - need[q[i].p1][q[i].s];
    q[i].ans += need2[q[i].b][q[i].s] - need2[q[i].p2][q[i].s];
    cout << q[i].ans << '\n';
  }
  return 0;
}
