#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int p = 31;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int n, q;
vector<pair<int, char> > g[N];
char sym[N];
int parent[N];
int answ[N], d[N];
int dp[N][18];
int tin[N], tout[N], timer;
long long pp[N];
void dfs(int v, int p, int r) {
  tin[v] = timer++;
  d[v] = r;
  dp[v][0] = parent[v];
  for (int i = 1; i <= 17; i++) dp[v][i] = dp[dp[v][i - 1]][i - 1];
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    parent[to] = v;
    sym[to] = g[v][i].second;
    dfs(to, v, r + 1);
  }
  tout[v] = timer++;
}
bool check(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (check(a, b)) return a;
  if (check(b, a)) return b;
  for (int i = 17; i >= 0; i--) {
    if (check(dp[a][i], b) == false) {
      a = dp[a][i];
    }
  }
  return parent[a];
}
int up(int a, int x) {
  for (int i = 0; i <= 17; i++) {
    if ((x >> i) & 1) {
      a = dp[a][i];
    }
  }
  return a;
}
int z[505];
int z_func(string &s, int sz) {
  z[0] = 0;
  int l = 0, r = 0;
  int answ = 0;
  for (int i = 1; i < (int)s.size(); i++) {
    int k = (i <= r) ? min(z[i - l], r - i + 1) : 0;
    while (i + k < (int)s.size() && s[k] == s[i + k]) {
      ++k;
    }
    if (i + k - 1 > r) {
      l = i;
      r = i + k - 1;
    }
    z[i] = k;
    if (i > sz && z[i] == sz) ++answ;
  }
  return answ;
}
vector<pair<int, pair<long long, int> > > off[N];
long long hsh[N];
int mas[N];
unordered_map<long long, int> mp;
int pos[N];
void solve(int v, int p, int k) {
  mp[hsh[v]]++;
  for (; pos[v] < (int)off[v].size(); pos[v]++) {
    int i = pos[v];
    if (off[v][i].first != k) break;
    long long H = off[v][i].second.first;
    int id = abs(off[v][i].second.second - 0);
    if (off[v][i].second.second < 0)
      answ[id] -= mp[H];
    else
      answ[id] += mp[H];
  }
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    solve(to, v, k);
  }
  mp[hsh[v]]--;
}
int main() {
  scanf("%d", &n);
  pp[0] = 1;
  for (int i = 1; i <= n; i++) {
    pp[i] = pp[i - 1] * 1ll * p;
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    char c;
    scanf("%d%d %c", &a, &b, &c);
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  parent[1] = 1;
  dfs(1, -1, 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int papa = lca(a, b);
    string s, S;
    cin >> s;
    long long H = 0, Hr = 0;
    for (int j = 0; j < (int)s.size(); j++) {
      H = H * 1ll * p + s[j] - 'a' + 1;
    }
    for (int j = (int)s.size() - 1; j >= 0; j--) {
      Hr = Hr * 1ll * p + s[j] - 'a' + 1;
    }
    S = s;
    S += '#';
    int len = min(d[a] - d[papa] + 1, (int)s.size());
    int gag = up(a, d[a] - d[papa] - len + 1);
    if (a != gag) {
      off[gag].push_back(make_pair((int)s.size(), make_pair(Hr, -i)));
      off[a].push_back(make_pair((int)s.size(), make_pair(Hr, i)));
    }
    while (gag != papa) {
      S += sym[gag];
      gag = parent[gag];
    }
    len = min(d[b] - d[papa] + 1, (int)s.size());
    gag = up(b, d[b] - d[papa] - len + 1);
    if (b != gag) {
      off[gag].push_back(make_pair((int)s.size(), make_pair(H, -i)));
      off[b].push_back(make_pair((int)s.size(), make_pair(H, i)));
    }
    vector<char> vec;
    while (gag != papa) {
      vec.push_back(sym[gag]);
      gag = parent[gag];
    }
    for (int i = (int)vec.size() - 1; i >= 0; i--) {
      S += vec[i];
    }
    answ[i] = z_func(S, (int)s.size());
  }
  for (int i = 1; i <= n; i++) {
    sort(off[i].begin(), off[i].end());
  }
  for (int i = 1; i <= n; i++) mas[i] = i;
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= n; j++) {
      if (mas[j] == 1)
        hsh[j] = 0;
      else
        hsh[j] = hsh[j] + pp[i - 1] * 1ll * (sym[mas[j]] - 'a' + 1);
      mas[j] = parent[mas[j]];
    }
    solve(1, -1, i);
    mp.clear();
  }
  for (int i = 1; i <= q; i++) {
    printf("%d\n", answ[i]);
  }
  return 0;
}
