#include <bits/stdc++.h>
using namespace std;
int n, m, fa[100010], dep[100010], w[100010][18 + 1], k, la[100010],
    ff[100010 * 2];
long long h[100010], mul[100010];
char s[100010], str[100010];
int po[100010], ans[100010];
int cnt, fst[10000007 + 1], nxt[10000007 + 1], g[10000007 + 1];
long long f[10000007 + 1];
struct node {
  int a, b;
  char c;
} e[100010 * 2];
struct info {
  long long ha;
  int inv, id;
};
vector<info> t[100010];
void add(int a, int b, char c) {
  e[++k] = (node){a, b, c};
  ff[k] = la[a];
  la[a] = k;
  e[++k] = (node){b, a, c};
  ff[k] = la[b];
  la[b] = k;
}
void insert(long long v, int val) {
  int x = (v % 10000007 + 10000007) % 10000007;
  for (int a = fst[x]; a; a = nxt[a])
    if (f[a] == v) {
      g[a] += val;
      return;
    }
  f[++cnt] = v;
  g[cnt] = val;
  nxt[cnt] = fst[x];
  fst[x] = cnt;
}
int qry(long long v) {
  int x = (v % 10000007 + 10000007) % 10000007;
  for (int a = fst[x]; a; a = nxt[a])
    if (f[a] == v) return g[a];
  return 0;
}
void dfs1(int x) {
  w[x][0] = fa[x];
  for (int i = 1; i <= 18; i++) w[x][i] = w[w[x][i - 1]][i - 1];
  for (int a = la[x]; a; a = ff[a]) {
    if (dep[e[a].b]) continue;
    fa[e[a].b] = x;
    s[e[a].b] = e[a].c;
    dep[e[a].b] = dep[x] + 1;
    dfs1(e[a].b);
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 18; i >= 0; i--)
    if (dep[w[x][i]] >= dep[y]) x = w[x][i];
  if (x == y) return x;
  for (int i = 18; i >= 0; i--)
    if (w[x][i] != w[y][i]) x = w[x][i], y = w[y][i];
  return w[x][0];
}
int find(int x, int d) {
  for (int i = 18; i >= 0; i--)
    if (dep[w[x][i]] >= d) x = w[x][i];
  return x;
}
long long get(int l, int r) { return h[r] - h[l - 1] * mul[r - l + 1]; }
void qry(int x, int y, char *str, int id) {
  int p = lca(x, y), a = x, b = y, tot = 0, A, B;
  int len = strlen(str), pos;
  long long ha = 0;
  for (int i = 0; i < len; i++) ha = ha * 19990213 + str[i];
  if (dep[x] - dep[p] >= len) a = find(x, dep[p] + len - 1);
  A = a;
  if (dep[y] - dep[p] >= len) b = find(y, dep[p] + len - 1);
  B = b;
  while (a != p) po[++tot] = a, a = fa[a];
  pos = tot;
  while (b != p) po[++tot] = b, b = fa[b];
  reverse(po + pos + 1, po + tot + 1);
  for (int i = 1; i <= tot; i++) h[i] = h[i - 1] * 19990213 + s[po[i]];
  for (int i = 1; i + len - 1 <= tot; i++)
    if (get(i, i + len - 1) == ha) ans[id]++;
  if (A != x) {
    t[x].push_back((info){ha, 1, id});
    t[A].push_back((info){ha, -1, id});
  }
  ha = 0;
  for (int i = len - 1; i >= 0; i--) ha = ha * 19990213 + str[i];
  if (B != y) {
    t[y].push_back((info){ha, 1, id});
    t[B].push_back((info){ha, -1, id});
  }
}
void dfs2(int x) {
  long long ha = 0;
  for (int i = 1, p = x; i <= 100 && p; p = fa[p], i++)
    insert(ha = ha * 19990213 + s[p], 1);
  for (int i = 0; i < t[x].size(); i++)
    ans[t[x][i].id] += t[x][i].inv * qry(t[x][i].ha);
  for (int a = la[x]; a; a = ff[a])
    if (dep[e[a].b] == dep[x] + 1) dfs2(e[a].b);
  ha = 0;
  for (int i = 1, p = x; i <= 100 && p; p = fa[p], i++)
    insert(ha = ha * 19990213 + s[p], -1);
}
int main() {
  int a, b, pos, len;
  char c;
  long long ha;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) scanf("%d%d %c", &a, &b, &c), add(a, b, c);
  dep[1] = 1;
  dfs1(1);
  mul[0] = 1;
  for (int i = 1; i <= n; i++) mul[i] = mul[i - 1] * 19990213;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d%d %s", &a, &b, str), qry(a, b, str, i);
  dfs2(1);
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
