#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#define pii pair<int,int>
#define piii pair< pii,int>
#define N_ 101000
using namespace std;
vector<int>E[N_], L[N_];
vector<piii>V[110];
int pL[N_], n, Dep[N_], par[N_][20], Num[N_], cnt, C[N_], PPP[N_], ReNum[N_];
long long BS = 1879, Mod[2] = { 1000000007,1000000009 }, po[N_][2];
void DFS(int a, int pp) {
	int i;
	C[a]++;
	par[a][0] = pp;
	for (i = 0; i < 18; i++)par[a][i+1] = par[par[a][i]][i];
	for (i = 0; i < E[a].size();i++) {
		int x = E[a][i];
		if (x == pp)continue;
		Dep[x] = Dep[a] + 1;
		pL[x] = L[a][i];
		DFS(x, a);
		C[a] += C[x];
	}
}
int Up(int a, int d) {
	int i = 0;
	while (d) {
		if (d & 1)a = par[a][i];
		i++; d >>= 1;
	}
	return a;
}
void HLD(int a, int ppp) {
	PPP[a] = ppp;
	Num[a] = ++cnt;
	ReNum[cnt] = a;
	int Mx = -1, pv = -1;
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (Mx < C[x])Mx = C[x], pv = x;
	}
	if (pv == -1) {
		return;
	}
	HLD(pv, ppp);
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (x != pv)HLD(x, x);
	}
}
int LCA(int a, int b) {
	if (Dep[a] < Dep[b])return LCA(b, a);
	a = Up(a, Dep[a] - Dep[b]);
	int i;
	for (i = 17; i >= 0; i--)if (par[a][i] != par[b][i])a = par[a][i], b = par[b][i];
	if (a != b)a = par[a][0];
	return a;
}
char p[110];
int m, w[110], q[220];
int Get(int b, int e, int z1, int z2) {
	return lower_bound(V[m].begin(), V[m].end(), piii(pii(z1,z2),e+1)) - lower_bound(V[m].begin(), V[m].end(), piii(pii(z1, z2),b));
}
int Go(int a, int pp, int z1, int z2) {
	int i;
	int l = Dep[a] - Dep[pp];
	if (l < m)return 0;
	int rp = Up(a, l - m), res = 0;
	while (1) {
		int t = PPP[a];
		if (Dep[t] <= Dep[rp]) {
			res += Get(Num[rp], Num[a], z1,z2);
			break;
		}
		else {
			res += Get(Num[t], Num[a], z1,z2);
			a = par[t][0];
		}
	}
	return res;
}
string GetString(int a, int pp, int L) {
	a = Up(a, max(Dep[a] - Dep[pp] - L, 0));
	string t = "";
	L = Dep[a] - Dep[pp];
	if (!L)return t;
	t.resize(L);
	int c = 0;
	while (a != pp) {
		t[c++] = pL[a] + 'a';
		a = par[a][0];
	}
	return t;
}
int oto[220];
int KMP(int LL) {
	int i, res = 0;
	oto[0] = -1;
	for (i = 0; i < m; i++) {
		int t = oto[i];
		while (t != -1 && w[i] != w[t])t = oto[t];
		oto[i + 1] = t + 1;
	}
	int pv = 0;
	for (i = 0; i < LL; i++) {
		while (pv != -1 && w[pv] != q[i])pv = oto[pv];
		pv++;
		if (pv == m)res++;
	}
	return res;
}
int main() {
	int i, a, b, j;
	char pp[3];
	po[0][0]=po[0][1] = 1;
	for (i = 1; i <= 100000; i++)for(j=0;j<2;j++)po[i][j] = po[i - 1][j] * BS % Mod[j];
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		scanf("%s", pp);
		E[a].push_back(b);
		E[b].push_back(a);
		L[a].push_back(pp[0] - 'a');
		L[b].push_back(pp[0] - 'a');
	}
	DFS(1, 0);
	HLD(1, 1);
	for (i = 1; i <= n; i++) {
		int x = i;
		long long s1 = 0, s2 = 0;
		for (j = 0; j < min(100, Dep[i]); j++) {
			s1 = (s2 * BS + pL[x]) % Mod[0];
			s2 = (s2 * BS + pL[x]) % Mod[1];
			x = par[x][0];
			V[j + 1].push_back({ {s1,s2},Num[i] });
		}
	}
	for (i = 1; i <= 100; i++)if (!V[i].empty())sort(V[i].begin(), V[i].end());
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d%d", &a, &b);
		scanf("%s", p);
		long long s1[2] = { 0,0 }, s2[2] = { 0,0 };
		for (i = 0; p[i]; i++)w[i] = p[i] - 'a';
		m = i;
		for (i = 0; p[i]; i++) {
			for (j = 0; j < 2; j++) {
				s1[j] = (s1[j] + w[i] * po[i][j]) % Mod[j];
				s2[j] = (s2[j] * BS + w[i]) % Mod[j];
			}
		}
		int l = LCA(a, b);
		int res = Go(a, l, s2[0],s2[1]);
		res += Go(b, l, s1[0],s1[1]);

		string t1 = GetString(a, l, m - 1);
		string t2 = GetString(b, l, m - 1);
		int c = 0;
		for (i = 0; i < t1.size(); i++)q[c++] = t1[i] - 'a';
		for (i = t2.size()-1; i >= 0; i--)q[c++] = t2[i] - 'a';
		res += KMP(c);
		printf("%d\n", res);
	}

}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#define pii pair<int,int>
#define piii pair< pii,int>
#define N_ 101000
using namespace std;
vector<int>E[N_], L[N_];
vector<piii>V[110];
int pL[N_], n, Dep[N_], par[N_][20], Num[N_], cnt, C[N_], PPP[N_], ReNum[N_];
long long BS = 26, Mod[2] = { 1000000007,998244353 }, po[N_][2];
void DFS(int a, int pp) {
	int i;
	C[a]++;
	par[a][0] = pp;
	for (i = 0; i < 18; i++)par[a][i+1] = par[par[a][i]][i];
	for (i = 0; i < E[a].size();i++) {
		int x = E[a][i];
		if (x == pp)continue;
		Dep[x] = Dep[a] + 1;
		pL[x] = L[a][i];
		DFS(x, a);
		C[a] += C[x];
	}
}
int Up(int a, int d) {
	int i = 0;
	while (d) {
		if (d & 1)a = par[a][i];
		i++; d >>= 1;
	}
	return a;
}
void HLD(int a, int ppp) {
	PPP[a] = ppp;
	Num[a] = ++cnt;
	ReNum[cnt] = a;
	int Mx = -1, pv = -1;
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (Mx < C[x])Mx = C[x], pv = x;
	}
	if (pv == -1) {
		return;
	}
	HLD(pv, ppp);
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (x != pv)HLD(x, x);
	}
}
int LCA(int a, int b) {
	if (Dep[a] < Dep[b])return LCA(b, a);
	a = Up(a, Dep[a] - Dep[b]);
	int i;
	for (i = 17; i >= 0; i--)if (par[a][i] != par[b][i])a = par[a][i], b = par[b][i];
	if (a != b)a = par[a][0];
	return a;
}
char p[110];
int m, w[110], q[220];
int Get(int b, int e, int z1, int z2) {
	return lower_bound(V[m].begin(), V[m].end(), piii(pii(z1,z2),e+1)) - lower_bound(V[m].begin(), V[m].end(), piii(pii(z1, z2),b));
}
int Go(int a, int pp, int z1, int z2) {
	int i;
	int l = Dep[a] - Dep[pp];
	if (l < m)return 0;
	int rp = Up(a, l - m), res = 0;
	while (1) {
		int t = PPP[a];
		if (Dep[t] <= Dep[rp]) {
			res += Get(Num[rp], Num[a], z1,z2);
			break;
		}
		else {
			res += Get(Num[t], Num[a], z1,z2);
			a = par[t][0];
		}
	}
	return res;
}
string GetString(int a, int pp, int L) {
	a = Up(a, max(Dep[a] - Dep[pp] - L, 0));
	string t = "";
	L = Dep[a] - Dep[pp];
	if (!L)return t;
	t.resize(L);
	int c = 0;
	while (a != pp) {
		t[c++] = pL[a] + 'a';
		a = par[a][0];
	}
	return t;
}
int oto[220];
int KMP(int LL) {
	int i, res = 0;
	oto[0] = -1;
	for (i = 0; i < m; i++) {
		int t = oto[i];
		while (t != -1 && w[i] != w[t])t = oto[t];
		oto[i + 1] = t + 1;
	}
	int pv = 0;
	for (i = 0; i < LL; i++) {
		while (pv != -1 && w[pv] != q[i])pv = oto[pv];
		pv++;
		if (pv == m)res++;
	}
	return res;
}
int main() {
	int i, a, b, j;
	char pp[3];
	po[0][0]=po[0][1] = 1;
	for (i = 1; i <= 100000; i++)for(j=0;j<2;j++)po[i][j] = po[i - 1][j] * BS % Mod[j];
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		scanf("%s", pp);
		E[a].push_back(b);
		E[b].push_back(a);
		L[a].push_back(pp[0] - 'a');
		L[b].push_back(pp[0] - 'a');
	}
	DFS(1, 0);
	HLD(1, 1);
	for (i = 1; i <= n; i++) {
		int x = i;
		long long s1 = 0, s2 = 0;
		for (j = 0; j < min(100, Dep[i]); j++) {
			s1 = (s2 * BS + pL[x]) % Mod[0];
			s2 = (s2 * BS + pL[x]) % Mod[1];
			x = par[x][0];
			V[j + 1].push_back({ {s1,s2},Num[i] });
		}
	}
	for (i = 1; i <= 100; i++)if (!V[i].empty())sort(V[i].begin(), V[i].end());
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d%d", &a, &b);
		scanf("%s", p);
		long long s1[2] = { 0,0 }, s2[2] = { 0,0 };
		for (i = 0; p[i]; i++)w[i] = p[i] - 'a';
		m = i;
		for (i = 0; p[i]; i++) {
			for (j = 0; j < 2; j++) {
				s1[j] = (s1[j] + w[i] * po[i][j]) % Mod[j];
				s2[j] = (s2[j] * BS + w[i]) % Mod[j];
			}
		}
		int l = LCA(a, b);
		int res = Go(a, l, s2[0],s2[1]);
		res += Go(b, l, s1[0],s1[1]);

		string t1 = GetString(a, l, m - 1);
		string t2 = GetString(b, l, m - 1);
		int c = 0;
		for (i = 0; i < t1.size(); i++)q[c++] = t1[i] - 'a';
		for (i = t2.size()-1; i >= 0; i--)q[c++] = t2[i] - 'a';
		res += KMP(c);
		printf("%d\n", res);
	}

}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#define pii pair<int,int>
#define piii pair< pii,int>
#define N_ 101000
using namespace std;
vector<int>E[N_], L[N_];
vector<piii>V[110];
int pL[N_], n, Dep[N_], par[N_][20], Num[N_], cnt, C[N_], PPP[N_], ReNum[N_];
long long BS = 27, Mod[2] = { 1000000007,1000000009 }, po[N_][2];
void DFS(int a, int pp) {
	int i;
	C[a]++;
	par[a][0] = pp;
	for (i = 0; i < 18; i++)par[a][i+1] = par[par[a][i]][i];
	for (i = 0; i < E[a].size();i++) {
		int x = E[a][i];
		if (x == pp)continue;
		Dep[x] = Dep[a] + 1;
		pL[x] = L[a][i];
		DFS(x, a);
		C[a] += C[x];
	}
}
int Up(int a, int d) {
	int i = 0;
	while (d) {
		if (d & 1)a = par[a][i];
		i++; d >>= 1;
	}
	return a;
}
void HLD(int a, int ppp) {
	PPP[a] = ppp;
	Num[a] = ++cnt;
	ReNum[cnt] = a;
	int Mx = -1, pv = -1;
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (Mx < C[x])Mx = C[x], pv = x;
	}
	if (pv == -1) {
		return;
	}
	HLD(pv, ppp);
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (x != pv)HLD(x, x);
	}
}
int LCA(int a, int b) {
	if (Dep[a] < Dep[b])return LCA(b, a);
	a = Up(a, Dep[a] - Dep[b]);
	int i;
	for (i = 17; i >= 0; i--)if (par[a][i] != par[b][i])a = par[a][i], b = par[b][i];
	if (a != b)a = par[a][0];
	return a;
}
char p[110];
int m, w[110], q[220];
int Get(int b, int e, int z1, int z2) {
	return lower_bound(V[m].begin(), V[m].end(), piii(pii(z1,z2),e+1)) - lower_bound(V[m].begin(), V[m].end(), piii(pii(z1, z2),b));
}
int Go(int a, int pp, int z1, int z2) {
	int i;
	int l = Dep[a] - Dep[pp];
	if (l < m)return 0;
	int rp = Up(a, l - m), res = 0;
	while (1) {
		int t = PPP[a];
		if (Dep[t] <= Dep[rp]) {
			res += Get(Num[rp], Num[a], z1,z2);
			break;
		}
		else {
			res += Get(Num[t], Num[a], z1,z2);
			a = par[t][0];
		}
	}
	return res;
}
string GetString(int a, int pp, int L) {
	a = Up(a, max(Dep[a] - Dep[pp] - L, 0));
	string t = "";
	L = Dep[a] - Dep[pp];
	if (!L)return t;
	t.resize(L);
	int c = 0;
	while (a != pp) {
		t[c++] = pL[a] + 'a';
		a = par[a][0];
	}
	return t;
}
int oto[220];
int KMP(int LL) {
	int i, res = 0;
	oto[0] = -1;
	for (i = 0; i < m; i++) {
		int t = oto[i];
		while (t != -1 && w[i] != w[t])t = oto[t];
		oto[i + 1] = t + 1;
	}
	int pv = 0;
	for (i = 0; i < LL; i++) {
		while (pv != -1 && w[pv] != q[i])pv = oto[pv];
		pv++;
		if (pv == m)res++;
	}
	return res;
}
int main() {
	int i, a, b, j;
	char pp[3];
	po[0][0]=po[0][1] = 1;
	for (i = 1; i <= 100000; i++)for(j=0;j<2;j++)po[i][j] = po[i - 1][j] * BS % Mod[j];
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		scanf("%s", pp);
		E[a].push_back(b);
		E[b].push_back(a);
		L[a].push_back(pp[0] - 'a' + 1);
		L[b].push_back(pp[0] - 'a' + 1);
	}
	DFS(1, 0);
	HLD(1, 1);
	for (i = 1; i <= n; i++) {
		int x = i;
		long long s1 = 0, s2 = 0;
		for (j = 0; j < min(100, Dep[i]); j++) {
			s1 = (s2 * BS + pL[x]) % Mod[0];
			s2 = (s2 * BS + pL[x]) % Mod[1];
			x = par[x][0];
			V[j + 1].push_back({ {s1,s2},Num[i] });
		}
	}
	for (i = 1; i <= 100; i++)if (!V[i].empty())sort(V[i].begin(), V[i].end());
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d%d", &a, &b);
		scanf("%s", p);
		long long s1[2] = { 0,0 }, s2[2] = { 0,0 };
		for (i = 0; p[i]; i++)w[i] = p[i] - 'a' + 1;
		m = i;
		for (i = 0; p[i]; i++) {
			for (j = 0; j < 2; j++) {
				s1[j] = (s1[j] + w[i] * po[i][j]) % Mod[j];
				s2[j] = (s2[j] * BS + w[i]) % Mod[j];
			}
		}
		int l = LCA(a, b);
		int res = Go(a, l, s2[0],s2[1]);
		res += Go(b, l, s1[0],s1[1]);

		string t1 = GetString(a, l, m - 1);
		string t2 = GetString(b, l, m - 1);
		int c = 0;
		for (i = 0; i < t1.size(); i++)q[c++] = t1[i] - 'a';
		for (i = t2.size()-1; i >= 0; i--)q[c++] = t2[i] - 'a';
		res += KMP(c);
		printf("%d\n", res);
	}

}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#define pii pair<int,int>
#define piii pair< pii,int>
#define N_ 101000
using namespace std;
vector<int>E[N_], L[N_];
vector<piii>V[110];
int pL[N_], n, Dep[N_], par[N_][20], Num[N_], cnt, C[N_], PPP[N_], ReNum[N_];
long long BS = 26, Mod[2] = { 1000000007,1000000009 }, po[N_][2];
void DFS(int a, int pp) {
	int i;
	C[a]++;
	par[a][0] = pp;
	for (i = 0; i < 18; i++)par[a][i+1] = par[par[a][i]][i];
	for (i = 0; i < E[a].size();i++) {
		int x = E[a][i];
		if (x == pp)continue;
		Dep[x] = Dep[a] + 1;
		pL[x] = L[a][i];
		DFS(x, a);
		C[a] += C[x];
	}
}
int Up(int a, int d) {
	int i = 0;
	while (d) {
		if (d & 1)a = par[a][i];
		i++; d >>= 1;
	}
	return a;
}
void HLD(int a, int ppp) {
	PPP[a] = ppp;
	Num[a] = ++cnt;
	ReNum[cnt] = a;
	int Mx = -1, pv = -1;
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (Mx < C[x])Mx = C[x], pv = x;
	}
	if (pv == -1) {
		return;
	}
	HLD(pv, ppp);
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (x != pv)HLD(x, x);
	}
}
int LCA(int a, int b) {
	if (Dep[a] < Dep[b])return LCA(b, a);
	a = Up(a, Dep[a] - Dep[b]);
	int i;
	for (i = 17; i >= 0; i--)if (par[a][i] != par[b][i])a = par[a][i], b = par[b][i];
	if (a != b)a = par[a][0];
	return a;
}
char p[110];
int m, w[110], q[220];
int Get(int b, int e, int z1, int z2) {
	return lower_bound(V[m].begin(), V[m].end(), piii(pii(z1,z2),e+1)) - lower_bound(V[m].begin(), V[m].end(), piii(pii(z1, z2),b));
}
int Go(int a, int pp, int z1, int z2) {
	int i;
	int l = Dep[a] - Dep[pp];
	if (l < m)return 0;
	int rp = Up(a, l - m), res = 0;
	while (1) {
		int t = PPP[a];
		if (Dep[t] <= Dep[rp]) {
			res += Get(Num[rp], Num[a], z1,z2);
			break;
		}
		else {
			res += Get(Num[t], Num[a], z1,z2);
			a = par[t][0];
		}
	}
	return res;
}
string GetString(int a, int pp, int L) {
	a = Up(a, max(Dep[a] - Dep[pp] - L, 0));
	string t = "";
	L = Dep[a] - Dep[pp];
	if (!L)return t;
	t.resize(L);
	int c = 0;
	while (a != pp) {
		t[c++] = pL[a] + 'a';
		a = par[a][0];
	}
	return t;
}
int oto[220];
int KMP(int LL) {
	int i, res = 0;
	oto[0] = -1;
	for (i = 0; i < m; i++) {
		int t = oto[i];
		while (t != -1 && w[i] != w[t])t = oto[t];
		oto[i + 1] = t + 1;
	}
	int pv = 0;
	for (i = 0; i < LL; i++) {
		while (pv != -1 && w[pv] != q[i])pv = oto[pv];
		pv++;
		if (pv == m)res++;
	}
	return res;
}
int main() {
	int i, a, b, j;
	char pp[3];
	po[0][0]=po[0][1] = 1;
	for (i = 1; i <= 100000; i++)for(j=0;j<2;j++)po[i][j] = po[i - 1][j] * BS % Mod[j];
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		scanf("%s", pp);
		E[a].push_back(b);
		E[b].push_back(a);
		L[a].push_back(pp[0] - 'a');
		L[b].push_back(pp[0] - 'a');
	}
	DFS(1, 0);
	HLD(1, 1);
	for (i = 1; i <= n; i++) {
		int x = i;
		long long s1 = 0, s2 = 0;
		for (j = 0; j < min(100, Dep[i]); j++) {
			s1 = (s2 * BS + pL[x]) % Mod[0];
			s2 = (s2 * BS + pL[x]) % Mod[1];
			x = par[x][0];
			V[j + 1].push_back({ {s1,s2},Num[i] });
		}
	}
	for (i = 1; i <= 100; i++)if (!V[i].empty())sort(V[i].begin(), V[i].end());
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d%d", &a, &b);
		scanf("%s", p);
		long long s1[2] = { 0,0 }, s2[2] = { 0,0 };
		for (i = 0; p[i]; i++)w[i] = p[i] - 'a';
		m = i;
		for (i = 0; p[i]; i++) {
			for (j = 0; j < 2; j++) {
				s1[j] = (s1[j] + w[i] * po[i][j]) % Mod[j];
				s2[j] = (s2[j] * BS + w[i]) % Mod[j];
			}
		}
		int l = LCA(a, b);
		int res = Go(a, l, s2[0],s2[1]);
		res += Go(b, l, s1[0],s1[1]);

		string t1 = GetString(a, l, m - 1);
		string t2 = GetString(b, l, m - 1);
		int c = 0;
		for (i = 0; i < t1.size(); i++)q[c++] = t1[i] - 'a';
		for (i = t2.size()-1; i >= 0; i--)q[c++] = t2[i] - 'a';
		res += KMP(c);
		printf("%d\n", res);
	}

}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#define pii pair<long long,int>
#define piii pair< pii,int>
#define N_ 101000
using namespace std;
vector<int>E[N_], L[N_];
vector<piii>V[110];
int pL[N_], n, Dep[N_], par[N_][20], Num[N_], cnt, C[N_], PPP[N_], ReNum[N_];
long long BS = 26, Mod[2] = { 100000000000007,1000000009 }, po[N_][2];
void DFS(int a, int pp) {
	int i;
	C[a]++;
	par[a][0] = pp;
	for (i = 0; i < 18; i++)par[a][i+1] = par[par[a][i]][i];
	for (i = 0; i < E[a].size();i++) {
		int x = E[a][i];
		if (x == pp)continue;
		Dep[x] = Dep[a] + 1;
		pL[x] = L[a][i];
		DFS(x, a);
		C[a] += C[x];
	}
}
int Up(int a, int d) {
	int i = 0;
	while (d) {
		if (d & 1)a = par[a][i];
		i++; d >>= 1;
	}
	return a;
}
void HLD(int a, int ppp) {
	PPP[a] = ppp;
	Num[a] = ++cnt;
	ReNum[cnt] = a;
	int Mx = -1, pv = -1;
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (Mx < C[x])Mx = C[x], pv = x;
	}
	if (pv == -1) {
		return;
	}
	HLD(pv, ppp);
	for (auto &x : E[a]) {
		if (x == par[a][0])continue;
		if (x != pv)HLD(x, x);
	}
}
int LCA(int a, int b) {
	if (Dep[a] < Dep[b])return LCA(b, a);
	a = Up(a, Dep[a] - Dep[b]);
	int i;
	for (i = 17; i >= 0; i--)if (par[a][i] != par[b][i])a = par[a][i], b = par[b][i];
	if (a != b)a = par[a][0];
	return a;
}
char p[110];
int m, w[110], q[220];
int Get(int b, int e, int z1, int z2) {
	return lower_bound(V[m].begin(), V[m].end(), piii(pii(z1,z2),e+1)) - lower_bound(V[m].begin(), V[m].end(), piii(pii(z1, z2),b));
}
int Go(int a, int pp, int z1, int z2) {
	int i;
	int l = Dep[a] - Dep[pp];
	if (l < m)return 0;
	int rp = Up(a, l - m), res = 0;
	while (1) {
		int t = PPP[a];
		if (Dep[t] <= Dep[rp]) {
			res += Get(Num[rp], Num[a], z1,z2);
			break;
		}
		else {
			res += Get(Num[t], Num[a], z1,z2);
			a = par[t][0];
		}
	}
	return res;
}
string GetString(int a, int pp, int L) {
	a = Up(a, max(Dep[a] - Dep[pp] - L, 0));
	string t = "";
	L = Dep[a] - Dep[pp];
	if (!L)return t;
	t.resize(L);
	int c = 0;
	while (a != pp) {
		t[c++] = pL[a] + 'a';
		a = par[a][0];
	}
	return t;
}
int oto[220];
int KMP(int LL) {
	int i, res = 0;
	oto[0] = -1;
	for (i = 0; i < m; i++) {
		int t = oto[i];
		while (t != -1 && w[i] != w[t])t = oto[t];
		oto[i + 1] = t + 1;
	}
	int pv = 0;
	for (i = 0; i < LL; i++) {
		while (pv != -1 && w[pv] != q[i])pv = oto[pv];
		pv++;
		if (pv == m)res++;
	}
	return res;
}
int main() {
	int i, a, b, j;
	char pp[3];
	po[0][0]=po[0][1] = 1;
	for (i = 1; i <= 100000; i++)for(j=0;j<2;j++)po[i][j] = po[i - 1][j] * BS % Mod[j];
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		scanf("%s", pp);
		E[a].push_back(b);
		E[b].push_back(a);
		L[a].push_back(pp[0] - 'a');
		L[b].push_back(pp[0] - 'a');
	}
	DFS(1, 0);
	HLD(1, 1);
	for (i = 1; i <= n; i++) {
		int x = i;
		long long s1 = 0, s2 = 0;
		for (j = 0; j < min(100, Dep[i]); j++) {
			s1 = (s2 * BS + pL[x]) % Mod[0];
			s2 = (s2 * BS + pL[x]) % Mod[1];
			x = par[x][0];
			V[j + 1].push_back({ {s1,s2},Num[i] });
		}
	}
	for (i = 1; i <= 100; i++)if (!V[i].empty())sort(V[i].begin(), V[i].end());
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d%d", &a, &b);
		scanf("%s", p);
		long long s1[2] = { 0,0 }, s2[2] = { 0,0 };
		for (i = 0; p[i]; i++)w[i] = p[i] - 'a';
		m = i;
		for (i = 0; p[i]; i++) {
			for (j = 0; j < 2; j++) {
				s1[j] = (s1[j] + w[i] * po[i][j]) % Mod[j];
				s2[j] = (s2[j] * BS + w[i]) % Mod[j];
			}
		}
		int l = LCA(a, b);
		int res = Go(a, l, s2[0],s2[1]);
		res += Go(b, l, s1[0],s1[1]);

		string t1 = GetString(a, l, m - 1);
		string t2 = GetString(b, l, m - 1);
		int c = 0;
		for (i = 0; i < t1.size(); i++)q[c++] = t1[i] - 'a';
		for (i = t2.size()-1; i >= 0; i--)q[c++] = t2[i] - 'a';
		res += KMP(c);
		printf("%d\n", res);
	}

}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

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<=20;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=20;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<=20;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<long long,int> > off[N];

long long hsh[N];
int mas[N];

unordered_map <long long,int> mp;

void solve(int v,int p){
    mp[hsh[v]]++;
    for(int i=0;i<(int)off[v].size();i++){
        long long H = off[v][i].first;
        int id = abs(off[v][i].second - 0);
        if(off[v][i].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);
    }
    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);
    assert(q != 100000);
    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);
        ///
        off[gag].push_back(make_pair(Hr , -i));
        off[a].push_back(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);
        ///
        off[gag].push_back(make_pair(H , -i));
        off[b].push_back(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++) 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);
    }
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

int tin[N] , tout[N] , timer;

long long pp[N];

long long hsh[N][102];

void dfs(int v,int p,int r){
    tin[v] = timer++;
    d[v] = r;
    ///
    dp[v][0] = parent[v];
    for(int i=1;i<=20;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=20;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<=20;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<long long,int> > off[N];

unordered_map <long long,int> mp;

void solve(int v,int p){
    for(int i=1;i<=100;i++){
        mp[hsh[v][i]]++;
    }
    for(int i=0;i<(int)off[v].size();i++){
        long long H = off[v][i].first;
        int id = abs(off[v][i].second - 0);
        if(off[v][i].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);
    }
    for(int i=1;i<=100;i++){
        mp[hsh[v][i]]--;
    }
}

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 ss = d[a] - d[papa] - len + 1;
        int gag = up(a , ss);
        ///
        off[gag].push_back(make_pair(Hr , -i));
        off[a].push_back(make_pair(Hr , i));
        ///
        while(gag != papa){
            S += sym[gag];
            gag = parent[gag];
        }
        ///
        len = min(d[b] - d[papa] + 1 , (int)s.size());
        ss = d[b] - d[papa] - len + 1;
        gag = up(b , ss);
        ///
        off[gag].push_back(make_pair(H , -i));
        off[b].push_back(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++){
        int x = min(d[i] - 1 , 100);
        int k = 0 , v = i;
        while(k < x){
            hsh[i][k + 1] = hsh[i][k] + pp[k] * 1ll * (sym[v] - 'a' + 1);
            v = parent[v];
            ++k;
        }
    }
    solve(1 , -1);
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

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<=20;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=20;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<=20;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<long long,int> > off[N];
vector <long long> hsh[N];

unordered_map <long long,int> mp;
unordered_map <long long,bool> mark;

void solve(int v,int p){
    for(int i=0;i<(int)hsh[v].size();i++){
        mp[hsh[v][i]]++;
    }
    for(int i=0;i<(int)off[v].size();i++){
        long long H = off[v][i].first;
        int id = abs(off[v][i].second - 0);
        if(off[v][i].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);
    }
    for(int i=0;i<(int)hsh[v].size();i++){
        mp[hsh[v][i]]--;
    }
}

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;
        }
        mark[H] = mark[Hr] = true;
        ///
        S = s;
        S += '#';
        ///
        int len = min(d[a] - d[papa] + 1 , (int)s.size());
        int ss = d[a] - d[papa] - len + 1;
        int gag = up(a , ss);
        ///
        off[gag].push_back(make_pair(Hr , -i));
        off[a].push_back(make_pair(Hr , i));
        ///
        while(gag != papa){
            S += sym[gag];
            gag = parent[gag];
        }
        ///
        len = min(d[b] - d[papa] + 1 , (int)s.size());
        ss = d[b] - d[papa] - len + 1;
        gag = up(b , ss);
        ///
        off[gag].push_back(make_pair(H , -i));
        off[b].push_back(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++){
        int x = min(d[i] - 1 , 100);
        int k = 0 , v = i;
        long long H = 0;
        while(k < x){
            H = H + pp[k] * 1ll * (sym[v] - 'a' + 1);
            if(mark[H]){
                hsh[i].push_back(H);
            }
            v = parent[v];
            ++k;
        }
    }
    solve(1 , -1);
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

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<=20;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=20;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<=20;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);
        ///
        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);
        ///
        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);
    }
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

int tin[N] , tout[N] , timer;

long long pp[N];

long long hsh[N][102];

void dfs(int v,int p,int r){
    tin[v] = timer++;
    d[v] = r;
    ///
    dp[v][0] = parent[v];
    for(int i=1;i<=20;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=20;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<=20;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<long long,int> > off[N];

map <long long,int> mp;

void solve(int v,int p){
    for(int i=1;i<=100;i++){
        mp[hsh[v][i]]++;
    }
    for(int i=0;i<(int)off[v].size();i++){
        long long H = off[v][i].first;
        int id = abs(off[v][i].second - 0);
        if(off[v][i].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);
    }
    for(int i=1;i<=100;i++){
        mp[hsh[v][i]]--;
    }
}

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 ss = d[a] - d[papa] - len + 1;
        int gag = up(a , ss);
        ///
        off[gag].push_back(make_pair(Hr , -i));
        off[a].push_back(make_pair(Hr , i));
        ///
        while(gag != papa){
            S += sym[gag];
            gag = parent[gag];
        }
        ///
        len = min(d[b] - d[papa] + 1 , (int)s.size());
        ss = d[b] - d[papa] - len + 1;
        gag = up(b , ss);
        ///
        off[gag].push_back(make_pair(H , -i));
        off[b].push_back(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++){
        int x = min(d[i] - 1 , 100);
        int k = 0 , v = i;
        while(k < x){
            hsh[i][k + 1] = hsh[i][k] + pp[k] * 1ll * (sym[v] - 'a' + 1);
            v = parent[v];
            ++k;
        }
    }
    solve(1 , -1);
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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);
    }
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

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<=20;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=20;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<=20;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<long long,int> > off[N];

long long hsh[N];
int mas[N];

unordered_map <long long,int> mp;

void solve(int v,int p){
    mp[hsh[v]]++;
    for(int i=0;i<(int)off[v].size();i++){
        long long H = off[v][i].first;
        int id = abs(off[v][i].second - 0);
        if(off[v][i].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);
    }
    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 ss = d[a] - d[papa] - len + 1;
        int gag = up(a , ss);
        ///
        off[gag].push_back(make_pair(Hr , -i));
        off[a].push_back(make_pair(Hr , i));
        ///
        while(gag != papa){
            S += sym[gag];
            gag = parent[gag];
        }
        ///
        len = min(d[b] - d[papa] + 1 , (int)s.size());
        ss = d[b] - d[papa] - len + 1;
        gag = up(b , ss);
        ///
        off[gag].push_back(make_pair(H , -i));
        off[b].push_back(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++) 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);
    }
    solve(1 , -1);
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

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<=20;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=20;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<=20;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<long long,int> > off[N];

long long hsh[N];
int mas[N];

unordered_map <long long,int> mp;

void solve(int v,int p){
    mp[hsh[v]]++;
    for(int i=0;i<(int)off[v].size();i++){
        long long H = off[v][i].first;
        int id = abs(off[v][i].second - 0);
        if(off[v][i].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);
    }
    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);
    assert(q == 100000);
    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);
        ///
        off[gag].push_back(make_pair(Hr , -i));
        off[a].push_back(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);
        ///
        off[gag].push_back(make_pair(H , -i));
        off[b].push_back(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++) 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);
    }
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


/////////////////////////   _LeMur_
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

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][22];

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<=20;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=20;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<=20;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<long long,int> > off[N];

long long hsh[N];
int mas[N];

unordered_map <long long,int> mp;
unordered_map <long long,bool> mark;

void solve(int v,int p){
    mp[hsh[v]]++;
    for(int i=0;i<(int)off[v].size();i++){
        long long H = off[v][i].first;
        int id = abs(off[v][i].second - 0);
        if(off[v][i].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);
    }
    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;
        }
        mark[H] = mark[Hr] = true;
        ///
        S = s;
        S += '#';
        ///
        int len = min(d[a] - d[papa] + 1 , (int)s.size());
        int ss = d[a] - d[papa] - len + 1;
        int gag = up(a , ss);
        ///
        off[gag].push_back(make_pair(Hr , -i));
        off[a].push_back(make_pair(Hr , i));
        ///
        while(gag != papa){
            S += sym[gag];
            gag = parent[gag];
        }
        ///
        len = min(d[b] - d[papa] + 1 , (int)s.size());
        ss = d[b] - d[papa] - len + 1;
        gag = up(b , ss);
        ///
        off[gag].push_back(make_pair(H , -i));
        off[b].push_back(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++) 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);
    }
    solve(1 , -1);
    for(int i=1;i<=q;i++){
        printf("%d\n",answ[i]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int N = 1e5, S = 100;
const int LOGN=20;

mt19937 rng;
struct basicHashing {
    int mod, mul;

    bool prime(int n) {
        for (int d = 2; d*d <= n; d++) if (n%d == 0) return false;
        return true;
    }

    void randomize() {
        rng.seed(time(0));
        mod = uniform_int_distribution<>(0, (int) 5e8)(rng) + 1e9;
        while (!prime(mod)) mod++;
        mul = uniform_int_distribution<>(2,mod-2)(rng);
    }

    basicHashing() { randomize(); init(); }

    vi h, pot;
    void init() {
        h.resize(1), pot.resize(1);
        h[0] = 0, pot[0] = 1;
    }

    void process(const string &s) {
        init();
        h.resize(si(s)+1);
        pot.resize(si(s)+1);
        forn(i,si(s)) h[i+1] = (((ll)h[i] * mul) + s[i]) % mod;
        forn(i,si(s)) pot[i+1] = (ll)pot[i] * mul % mod;
    }

    int hash(int i, int j) {
        int res = h[j] - (ll)h[i] * pot[j-i] % mod;
        if (res < 0) res += mod;
        return res;
    }

    int hash(const string &s) {
        int res = 0;
        for (char c : s) res = ((ll)res * mul + c) % mod;
        return res;
    }

    void push(char c) {
        h.pb(((ll)h.back() * mul + c) % mod);
        pot.pb((ll)pot.back() * mul % mod);
    }

    void pop() {
        h.pop_back(), pot.pop_back();
    }
};

struct hashing {
    basicHashing h1, h2;

    void process(const string &s) {
        h1.process(s), h2.process(s);
    }

    void init() {
        h1.init(), h2.init();
    }

    ll hash(int i, int j) {
        return ((ll)h1.hash(i, j)<<31)+h2.hash(i, j);
    }

    ll hash(const string &s) {
        return ((ll)h1.hash(s)<<31)+h2.hash(s);
    }

    void push(char c) {
        h1.push(c), h2.push(c);
    }

    void pop() {
        h1.pop(), h2.pop();
    }
} h;

struct Query {
    int op, ind; ll hash;
    Query(int _op, int _ind, ll _hash) : op(_op), ind(_ind), hash(_hash) {}
};

vector<pair<int, char>> adj[N];

//f[v][k] holds the 2^k father of v
//L[v] holds the level of v
int f[N][LOGN], L[N]; //INICIALIZAR N!!!!!!!!!!!!!!
char fch[N];
//call before build:
void dfs(int u=0, int fa=-1, char fc=0, int lvl=0){ // generate required data
	f[u][0]=fa, fch[u]=fc, L[u]=lvl;
	for (auto [v, c] : adj[u]) if (v != fa) dfs(v, u, c, lvl+1);
}
void build(){//f[i][0] must be filled previously, O(nlgn)
	forn(k, LOGN-1) forn(i, N) if (f[i][k]!=-1) f[i][k+1]=f[f[i][k]][k];
}
#define lg(x) (31-__builtin_clz(x))//=floor(log2(x))
int climb(int a, int d){//O(lgn)
	if (!d) return a;
	dforsn(i, 0, lg(L[a])+1) if (1<<i<=d) a=f[a][i], d-=1<<i;
    return a;
}
int lca(int a, int b){//O(lgn)
	if (L[a]<L[b]) swap(a, b);
	a = climb(a, L[a]-L[b]);
	if (a==b) return a;
	dforsn(i, 0, lg(L[a])+1) if (f[a][i]!=f[b][i]) a=f[a][i], b=f[b][i];
	return f[a][0];
}
int dist(int a, int b) {//returns distance between nodes
	return L[a]+L[b]-2*L[lca(a, b)];
}

int ans[N];
vector<Query> queries[N];
unordered_map<ll, int> active;

void go(int u = 0, int p = -1) {
    int sz = L[u];
    forsn(k, 1, min(sz, S)+1)
        active[h.hash(sz-k, sz)]++;

    for (auto [op, ind, hash] : queries[u])
        ans[ind] += op*active[hash];

    for (auto [v, c] : adj[u]) if (v != p) {
        h.push(c);
        go(v, u);
        h.pop();
    }

    forsn(k, 1, min(sz, S)+1)
        active[h.hash(sz-k, sz)]--;
}

int main() {
	fastio;

    int n; cin >> n;
    forn(_, n-1) {
        int u, v; char c; cin >> u >> v >> c; u--, v--;
        adj[u].pb(v, c);
        adj[v].pb(u, c);
    }

    dfs();
    build();

    int qs; cin >> qs;
    forn(q, qs) {
        int u, v; string s; cin >> u >> v >> s; u--, v--;
        int m = si(s);

        //cerr << "query " << u+1 << ' ' << v+1 << ' ' << s << endl;

        int w = lca(u, v);
        ll y = h.hash(s);
        reverse(all(s));
        ll yr = h.hash(s);

        queries[u].pb(1, q, yr);
        queries[v].pb(1, q, y);

        u = climb(u, max(0, L[u] - (L[w] + m - 1)));
        v = climb(v, max(0, L[v] - (L[w] + m - 1)));
        //cerr << "subo " << u+1 << ' ' << v+1 << endl;
        queries[u].pb(-1, q, yr);
        queries[v].pb(-1, q, y);

        if (w == u || w == v) continue;

        string t;
        while (u != w) {
            t += fch[u];
            u = f[u][0];
        }
        string temp;
        while (v != w) {
            temp += fch[v];
            v = f[v][0];
        }
        reverse(all(temp));
        t += temp;

        //cerr << "short path " << u << ' ' << v << ' ' << t << endl;

        h.process(t);
        forn(i, si(t) - m + 1) {
            ll x = h.hash(i, i + m);
            if (x == y) ans[q]++;
        }
    }

    h.init();
    go();

    forn(i, qs) cout << ans[i] << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int N = 1e5, S = 100;
const int LOGN=20;

mt19937 rng;
struct basicHashing {
    int mod, mul;

    bool prime(int n) {
        for (int d = 2; d*d <= n; d++) if (n%d == 0) return false;
        return true;
    }

    void randomize() {
        rng.seed(chrono::steady_clock::now().time_since_epoch().count());
        mod = uniform_int_distribution<>(0, (int) 5e8)(rng) + 1e9;
        while (!prime(mod)) mod++;
        mul = uniform_int_distribution<>(2,mod-2)(rng);
    }

    basicHashing() { init(); randomize(); }

    vi h, pot;
    void init() {
        h.resize(1), pot.resize(1);
        h[0] = 0, pot[0] = 1;
    }

    void process(const string &s) {
        init();
        h.resize(si(s)+1);
        pot.resize(si(s)+1);
        forn(i,si(s)) h[i+1] = (((ll)h[i] * mul) + s[i]) % mod;
        forn(i,si(s)) pot[i+1] = (ll)pot[i] * mul % mod;
    }

    int hash(int i, int j) {
        int res = h[j] - (ll)h[i] * pot[j-i] % mod;
        if (res < 0) res += mod;
        return res;
    }

    int hash(const string &s) {
        int res = 0;
        for (char c : s) res = ((ll)res * mul + c) % mod;
        return res;
    }

    void push(char c) {
        h.pb(((ll)h.back() * mul + c) % mod);
        pot.pb((ll)pot.back() * mul % mod);
    }

    void pop() {
        h.pop_back(), pot.pop_back();
    }
};

struct hashing {
    basicHashing h1, h2;

    void process(const string &s) {
        h1.process(s), h2.process(s);
    }

    void init() {
        h1.init(), h2.init();
    }

    string base2(ll x) {
        string ans;
        while (x > 0) {
            if (x&1) ans += '1'; else ans += '0';
            x /= 2;
        }
        return ans;
    }

    ll hash(int i, int j) {
        cerr << base2(h1.hash(i, j)) << ' ' << base2(h2.hash(i, j)) << ' ' << base2(((ll)h1.hash(i, j)<<32)+h2.hash(i, j)) << endl;
        return ((ll)h1.hash(i, j)<<32)+h2.hash(i, j);
    }

    ll hash(const string &s) {
        return ((ll)h1.hash(s)<<32)+h2.hash(s);
    }

    void push(char c) {
        h1.push(c), h2.push(c);
    }

    void pop() {
        h1.pop(), h2.pop();
    }
} h;

struct Query {
    int op, ind; ll hash;
    Query(int _op, int _ind, ll _hash) : op(_op), ind(_ind), hash(_hash) {}
};

vector<pair<int, char>> adj[N];

//f[v][k] holds the 2^k father of v
//L[v] holds the level of v
int f[N][LOGN], L[N]; //INICIALIZAR N!!!!!!!!!!!!!!
char fch[N];
//call before build:
void dfs(int u=0, int fa=-1, char fc=0, int lvl=0){ // generate required data
	f[u][0]=fa, fch[u]=fc, L[u]=lvl;
	for (auto [v, c] : adj[u]) if (v != fa) dfs(v, u, c, lvl+1);
}
void build(){//f[i][0] must be filled previously, O(nlgn)
	forn(k, LOGN-1) forn(i, N) if (f[i][k]!=-1) f[i][k+1]=f[f[i][k]][k];
}
#define lg(x) (31-__builtin_clz(x))//=floor(log2(x))
int climb(int a, int d){//O(lgn)
	if (!d) return a;
	dforsn(i, 0, lg(L[a])+1) if (1<<i<=d) a=f[a][i], d-=1<<i;
    return a;
}
int lca(int a, int b){//O(lgn)
	if (L[a]<L[b]) swap(a, b);
	a = climb(a, L[a]-L[b]);
	if (a==b) return a;
	dforsn(i, 0, lg(L[a])+1) if (f[a][i]!=f[b][i]) a=f[a][i], b=f[b][i];
	return f[a][0];
}
int dist(int a, int b) {//returns distance between nodes
	return L[a]+L[b]-2*L[lca(a, b)];
}

int ans[N];
vector<Query> queries[N];
unordered_map<ll, int> active;

void go(int u = 0, int p = -1) {
    int sz = L[u];
    forsn(k, 1, min(sz, S)+1)
        active[h.hash(sz-k, sz)]++;

    for (auto [op, ind, hash] : queries[u])
        ans[ind] += op*active[hash];

    for (auto [v, c] : adj[u]) if (v != p) {
        h.push(c);
        go(v, u);
        h.pop();
    }

    forsn(k, 1, min(sz, S)+1)
        active[h.hash(sz-k, sz)]--;
}

int main() {
	fastio;

    int n; cin >> n;
    forn(_, n-1) {
        int u, v; char c; cin >> u >> v >> c; u--, v--;
        adj[u].pb(v, c);
        adj[v].pb(u, c);
    }

    dfs();
    build();

    int qs; cin >> qs;
    forn(q, qs) {
        int u, v; string s; cin >> u >> v >> s; u--, v--;
        int m = si(s);

        //cerr << "query " << u+1 << ' ' << v+1 << ' ' << s << endl;

        int w = lca(u, v);
        ll y = h.hash(s);
        reverse(all(s));
        ll yr = h.hash(s);

        queries[u].pb(1, q, yr);
        queries[v].pb(1, q, y);

        u = climb(u, max(0, L[u] - (L[w] + m - 1)));
        v = climb(v, max(0, L[v] - (L[w] + m - 1)));
        //cerr << "subo " << u+1 << ' ' << v+1 << endl;
        queries[u].pb(-1, q, yr);
        queries[v].pb(-1, q, y);

        if (w == u || w == v) continue;

        string t;
        while (u != w) {
            t += fch[u];
            u = f[u][0];
        }
        string temp;
        while (v != w) {
            temp += fch[v];
            v = f[v][0];
        }
        reverse(all(temp));
        t += temp;

        //cerr << "short path " << u << ' ' << v << ' ' << t << endl;

        h.process(t);
        forn(i, si(t) - m + 1) {
            ll x = h.hash(i, i + m);
            if (x == y) ans[q]++;
        }
    }

    h.init();
    go();

    forn(i, qs) cout << ans[i] << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int N = 1e5, S = 100;
const int LOGN=20;

mt19937 rng;
struct basicHashing {
    int mod, mul;

    bool prime(int n) {
        for (int d = 2; d*d <= n; d++) if (n%d == 0) return false;
        return true;
    }

    void randomize() {
        rng.seed(time(0));
        mod = uniform_int_distribution<>(0, (int) 5e8)(rng) + 1e9;
        while (!prime(mod)) mod++;
        mul = uniform_int_distribution<>(2,mod-2)(rng);
    }

    basicHashing() { randomize(); init(); }

    vi h, pot;
    void init() {
        h.resize(1), pot.resize(1);
        h[0] = 0, pot[0] = 1;
    }

    void process(const string &s) {
        init();
        h.resize(si(s)+1);
        pot.resize(si(s)+1);
        forn(i,si(s)) h[i+1] = (((ll)h[i] * mul) + s[i]) % mod;
        forn(i,si(s)) pot[i+1] = (ll)pot[i] * mul % mod;
    }

    int hash(int i, int j) {
        int res = h[j] - (ll)h[i] * pot[j-i] % mod;
        if (res < 0) res += mod;
        return res;
    }

    int hash(const string &s) {
        int res = 0;
        for (char c : s) res = ((ll)res * mul + c) % mod;
        return res;
    }

    void push(char c) {
        h.pb(((ll)h.back() * mul + c) % mod);
        pot.pb((ll)pot.back() * mul % mod);
    }

    void pop() {
        h.pop_back(), pot.pop_back();
    }
};

struct hashing {
    basicHashing h1, h2;

    void process(const string &s) {
        h1.process(s), h2.process(s);
    }

    void init() {
        h1.init(), h2.init();
    }

    pii hash(int i, int j) {
        return {h1.hash(i, j), h2.hash(i, j)};
    }

    pii hash(const string &s) {
        return {h1.hash(s), h2.hash(s)};
    }

    void push(char c) {
        h1.push(c), h2.push(c);
    }

    void pop() {
        h1.pop(), h2.pop();
    }
} h;

struct Query {
    int op, ind; pii hash;
    Query(int _op, int _ind, pii _hash) : op(_op), ind(_ind), hash(_hash) {}
};

vector<pair<int, char>> adj[N];

//f[v][k] holds the 2^k father of v
//L[v] holds the level of v
int f[N][LOGN], L[N]; //INICIALIZAR N!!!!!!!!!!!!!!
char fch[N];
//call before build:
void dfs(int u=0, int fa=-1, char fc=0, int lvl=0){ // generate required data
	f[u][0]=fa, fch[u]=fc, L[u]=lvl;
	for (auto [v, c] : adj[u]) if (v != fa) dfs(v, u, c, lvl+1);
}
void build(){//f[i][0] must be filled previously, O(nlgn)
	forn(k, LOGN-1) forn(i, N) if (f[i][k]!=-1) f[i][k+1]=f[f[i][k]][k];
}
#define lg(x) (31-__builtin_clz(x))//=floor(log2(x))
int climb(int a, int d){//O(lgn)
	if (!d) return a;
	dforsn(i, 0, lg(L[a])+1) if (1<<i<=d) a=f[a][i], d-=1<<i;
    return a;
}
int lca(int a, int b){//O(lgn)
	if (L[a]<L[b]) swap(a, b);
	a = climb(a, L[a]-L[b]);
	if (a==b) return a;
	dforsn(i, 0, lg(L[a])+1) if (f[a][i]!=f[b][i]) a=f[a][i], b=f[b][i];
	return f[a][0];
}
int dist(int a, int b) {//returns distance between nodes
	return L[a]+L[b]-2*L[lca(a, b)];
}

int ans[N];
vector<Query> queries[N];
map<pii, int> active;

void go(int u = 0, int p = -1) {
    int sz = L[u];
    forsn(k, 1, min(sz, S)+1)
        active[h.hash(sz-k, sz)]++;

    for (auto [op, ind, hash] : queries[u])
        ans[ind] += op*active[hash];

    for (auto [v, c] : adj[u]) if (v != p) {
        h.push(c);
        go(v, u);
        h.pop();
    }

    forsn(k, 1, min(sz, S)+1)
        active[h.hash(sz-k, sz)]--;
}

int main() {
	fastio;

    int n; cin >> n;
    forn(_, n-1) {
        int u, v; char c; cin >> u >> v >> c; u--, v--;
        adj[u].pb(v, c);
        adj[v].pb(u, c);
    }

    dfs();
    build();

    int qs; cin >> qs;
    forn(q, qs) {
        int u, v; string s; cin >> u >> v >> s; u--, v--;
        int m = si(s);

        //cerr << "query " << u+1 << ' ' << v+1 << ' ' << s << endl;

        int w = lca(u, v);
        pii y = h.hash(s);
        reverse(all(s));
        pii yr = h.hash(s);

        queries[u].pb(1, q, yr);
        queries[v].pb(1, q, y);

        u = climb(u, max(0, L[u] - (L[w] + m - 1)));
        v = climb(v, max(0, L[v] - (L[w] + m - 1)));
        //cerr << "subo " << u+1 << ' ' << v+1 << endl;
        queries[u].pb(-1, q, yr);
        queries[v].pb(-1, q, y);

        if (w == u || w == v) continue;

        string t;
        while (u != w) {
            t += fch[u];
            u = f[u][0];
        }
        string temp;
        while (v != w) {
            temp += fch[v];
            v = f[v][0];
        }
        reverse(all(temp));
        t += temp;

        //cerr << "short path " << u << ' ' << v << ' ' << t << endl;

        h.process(t);
        forn(i, si(t) - m + 1) {
            pii x = h.hash(i, i + m);
            if (x == y) ans[q]++;
        }
    }

    h.init();
    go();

    forn(i, qs) cout << ans[i] << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int N = 1e5, S = 100;
const int LOGN=20;

mt19937 rng;
struct basicHashing {
    int mod, mul;

    bool prime(int n) {
        for (int d = 2; d*d <= n; d++) if (n%d == 0) return false;
        return true;
    }

    void randomize() {
        rng.seed(chrono::steady_clock::now().time_since_epoch().count());
        mod = uniform_int_distribution<>(0, (int) 5e8)(rng) + 1e9;
        while (!prime(mod)) mod++;
        mul = uniform_int_distribution<>(2,mod-2)(rng);
    }

    basicHashing() { init(); randomize(); }

    vi h, pot;
    void init() {
        h.resize(1), pot.resize(1);
        h[0] = 0, pot[0] = 1;
    }

    void process(const string &s) {
        init();
        h.resize(si(s)+1);
        pot.resize(si(s)+1);
        forn(i,si(s)) h[i+1] = (((ll)h[i] * mul) + s[i]) % mod;
        forn(i,si(s)) pot[i+1] = (ll)pot[i] * mul % mod;
    }

    int hash(int i, int j) {
        int res = h[j] - (ll)h[i] * pot[j-i] % mod;
        if (res < 0) res += mod;
        return res;
    }

    int hash(const string &s) {
        int res = 0;
        for (char c : s) res = ((ll)res * mul + c) % mod;
        return res;
    }

    void push(char c) {
        h.pb(((ll)h.back() * mul + c) % mod);
        pot.pb((ll)pot.back() * mul % mod);
    }

    void pop() {
        h.pop_back(), pot.pop_back();
    }
};

struct hashing {
    basicHashing h1, h2;

    void process(const string &s) {
        h1.process(s), h2.process(s);
    }

    void init() {
        h1.init(), h2.init();
    }

    ll hash(int i, int j) {
        return ((ll)h1.hash(i, j)<<32)+h2.hash(i, j);
    }

    ll hash(const string &s) {
        return ((ll)h1.hash(s)<<32)+h2.hash(s);
    }

    void push(char c) {
        h1.push(c), h2.push(c);
    }

    void pop() {
        h1.pop(), h2.pop();
    }
} h;

struct Query {
    int op, ind; ll hash;
    Query(int _op, int _ind, ll _hash) : op(_op), ind(_ind), hash(_hash) {}
};

vector<pair<int, char>> adj[N];

//f[v][k] holds the 2^k father of v
//L[v] holds the level of v
int f[N][LOGN], L[N]; //INICIALIZAR N!!!!!!!!!!!!!!
char fch[N];
//call before build:
void dfs(int u=0, int fa=-1, char fc=0, int lvl=0){ // generate required data
	f[u][0]=fa, fch[u]=fc, L[u]=lvl;
	for (auto [v, c] : adj[u]) if (v != fa) dfs(v, u, c, lvl+1);
}
void build(){//f[i][0] must be filled previously, O(nlgn)
	forn(k, LOGN-1) forn(i, N) if (f[i][k]!=-1) f[i][k+1]=f[f[i][k]][k];
}
#define lg(x) (31-__builtin_clz(x))//=floor(log2(x))
int climb(int a, int d){//O(lgn)
	if (!d) return a;
	dforsn(i, 0, lg(L[a])+1) if (1<<i<=d) a=f[a][i], d-=1<<i;
    return a;
}
int lca(int a, int b){//O(lgn)
	if (L[a]<L[b]) swap(a, b);
	a = climb(a, L[a]-L[b]);
	if (a==b) return a;
	dforsn(i, 0, lg(L[a])+1) if (f[a][i]!=f[b][i]) a=f[a][i], b=f[b][i];
	return f[a][0];
}
int dist(int a, int b) {//returns distance between nodes
	return L[a]+L[b]-2*L[lca(a, b)];
}

int ans[N];
vector<Query> queries[N];
unordered_map<ll, int> active;

void go(int u = 0, int p = -1) {
    int sz = L[u];
    forsn(k, 1, min(sz, S)+1) {
        ll hash = h.hash(sz-k, sz);
        if (active.count(hash)) active[hash]++;
    }

    for (auto [op, ind, hash] : queries[u])
        ans[ind] += op*active[hash];

    for (auto [v, c] : adj[u]) if (v != p) {
        h.push(c);
        go(v, u);
        h.pop();
    }

    forsn(k, 1, min(sz, S)+1) {
        ll hash = h.hash(sz-k, sz);
        if (active.count(hash)) active[hash]--;
    }
}

int main() {
	fastio;

    int n; cin >> n;
    forn(_, n-1) {
        int u, v; char c; cin >> u >> v >> c; u--, v--;
        adj[u].pb(v, c);
        adj[v].pb(u, c);
    }

    dfs();
    build();

    int qs; cin >> qs;
    forn(q, qs) {
        int u, v; string s; cin >> u >> v >> s; u--, v--;
        int m = si(s);

        //cerr << "query " << u+1 << ' ' << v+1 << ' ' << s << endl;

        int w = lca(u, v);
        ll y = h.hash(s);
        reverse(all(s));
        ll yr = h.hash(s);

        active[y] = 0;
        active[yr] = 0;

        queries[u].pb(1, q, yr);
        queries[v].pb(1, q, y);

        u = climb(u, max(0, L[u] - (L[w] + m - 1)));
        v = climb(v, max(0, L[v] - (L[w] + m - 1)));
        //cerr << "subo " << u+1 << ' ' << v+1 << endl;
        queries[u].pb(-1, q, yr);
        queries[v].pb(-1, q, y);

        if (w == u || w == v) continue;

        string t;
        while (u != w) {
            t += fch[u];
            u = f[u][0];
        }
        string temp;
        while (v != w) {
            temp += fch[v];
            v = f[v][0];
        }
        reverse(all(temp));
        t += temp;

        //cerr << "short path " << u << ' ' << v << ' ' << t << endl;

        h.process(t);
        forn(i, si(t) - m + 1) {
            ll x = h.hash(i, i + m);
            if (x == y) ans[q]++;
        }
    }

    h.init();
    go();

    forn(i, qs) cout << ans[i] << endl;

	return 0;
}


#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

using hsh = ull;
const int MAXN = 120000;
const int LOG = 20;
const hsh P = 23917;

int n;
vector<pair<int, char>> eds[MAXN];
int aa[MAXN];
int bb[MAXN];
string s[MAXN];
int up[MAXN][LOG];
char pc[MAXN];
int tm1;
int tin[MAXN];
int tout[MAXN];
int h[MAXN];

void dfs1(int v, int p) {
	tin[v] = tm1++;
	up[v][0] = p;
	for (int i = 1; i < LOG; ++i)
		up[v][i] = up[up[v][i - 1]][i - 1];
	for (auto e: eds[v]) {
		if (e.first == p)
			continue;
		h[e.first] = h[v] + 1;
		pc[e.first] = e.second;
		dfs1(e.first, v);
	}
	tout[v] = tm1;
}

bool is_p(int a, int b) {
	return tin[a] <= tin[b] && tin[b] < tout[a];
}

int lca(int a, int b) {
	if (is_p(a, b))
		return a;
	if (is_p(b, a))
		return b;
	for (int i = LOG - 1; i >= 0; --i) {
		if (!is_p(up[a][i], b))
			a = up[a][i];
	}
	return up[a][0];
}

int goup(int a, int h) {
	for (int i = LOG - 1; i >= 0; --i) {
		if (h >= (1 << i))
			h -= (1 << i), a = up[a][i];
	}
	return a;
}

hsh geths(const string &s) {
	hsh hs = 0;
	for (int i = 0; i < s.size(); ++i)
		hs = hs * P + s[i];
	return hs;
}

hsh pw[MAXN];
int ans[MAXN];
vector<hsh> vv;
vector<tuple<hsh, int, int>> go[MAXN];

void add(int v, hsh hs, int k, int d) {
	go[v].emplace_back(hs, k, d);
}

int lst[MAXN];
int cc[MAXN];
vector<char> st;

void dfs2(int v, int p) {
	if (v != 0)
		st.push_back(pc[v]);
	vector<pair<int, int>> undo;
	hsh hs = 0;
	for (int i = (int)st.size() - 1; i >= 0 && i >= (int)st.size() - 100; --i) {
		hs = hs * P + st[i];
		int pos = lower_bound(ALL(vv), hs) - vv.begin();
		if (pos == vv.size() || vv[pos] != hs)
			continue;
		undo.emplace_back(pos, lst[pos]);
		++cc[pos];
	}

	for (auto q: go[v]) {
		hsh hs; int k, d;
		tie(hs, k, d) = q;
		int pos = lower_bound(ALL(vv), hs) - vv.begin();
		if (pos == vv.size() || vv[pos] != hs)
			continue;
		ans[k] += d * cc[pos];
	}
	for (auto e: eds[v]) {
		if (e.first == p)
			continue;
		dfs2(e.first, v);
	}

	for (auto p: undo) {
		--cc[p.first];
		lst[p.first] = p.second;
	}
	if (v != 0)
		st.pop_back();
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	pw[0] = 1;
	for (int i = 1; i < MAXN; ++i)
		pw[i] = (pw[i - 1] * P);
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		char c;
		cin >> a >> b;
		--a, --b;
		cin >> c;
		eds[a].emplace_back(b, c);
		eds[b].emplace_back(a, c);
	}
	dfs1(0, 0);
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> aa[i] >> bb[i];
		--aa[i], --bb[i];
		cin >> s[i];
		int x = lca(aa[i], bb[i]);
		int a = aa[i];
		int b = bb[i];
		int ga = a;
		if (h[a] - h[x] > s[i].size() - 1)
			ga = goup(a, h[a] - h[x] - (s[i].size() - 1));
		int gb = b;
		if (h[b] - h[x] > s[i].size() - 1)
			gb = goup(b, h[b] - h[x] - (s[i].size() - 1));
		string s2;
		string tmp;
		int cur = ga;
		while (cur != x)
			s2 += pc[cur], cur = up[cur][0];
		cur = gb;
		while (cur != x)
			tmp += pc[cur], cur = up[cur][0];
		reverse(ALL(tmp));
		s2 += tmp;
		hsh hs = geths(s[i]);
		if (s2.size() >= s[i].size()) {
			hsh now = 0;
			for (int j = 0; j < s[i].size(); ++j)
				now = now * P + s2[j];
			if (now == hs)
				++ans[i];
			for (int j = s[i].size(); j < s2.size(); ++j) {
				now = now * P + s2[j];
				now -= pw[s[i].size()] * s2[j - s[i].size()];
				if (now == hs)
					++ans[i];
			}
		}
		vv.push_back(hs);
		add(a, hs, i, 1);
		add(ga, hs, i, -1);
		reverse(ALL(s[i]));
		hs = geths(s[i]);
		vv.push_back(hs);
		add(b, hs, i, 1);
		add(gb, hs, i, -1);
	}
	sort(ALL(vv));
	vv.resize(unique(ALL(vv)) - vv.begin());
	for (int i = 0; i < vv.size(); ++i)
		lst[i] = -1, cc[i] = 0;
	dfs2(0, -1);
	for (int i = 0; i < q; ++i)
		cout << ans[i] << "\n";
	return 0;
}


#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

using hsh = ull;
const int MAXN = 120000;
const int LOG = 20;
const hsh P = 23917;

int n;
vector<pair<int, char>> eds[MAXN];
int aa[MAXN];
int bb[MAXN];
string s[MAXN];
int up[MAXN][LOG];
char pc[MAXN];
int tm1;
int tin[MAXN];
int tout[MAXN];
int h[MAXN];

void dfs1(int v, int p) {
	tin[v] = tm1++;
	up[v][0] = p;
	for (int i = 1; i < LOG; ++i)
		up[v][i] = up[up[v][i - 1]][i - 1];
	for (auto e: eds[v]) {
		if (e.first == p)
			continue;
		h[e.first] = h[v] + 1;
		pc[e.first] = e.second;
		dfs1(e.first, v);
	}
	tout[v] = tm1;
}

bool is_p(int a, int b) {
	return tin[a] <= tin[b] && tin[b] < tout[a];
}

int lca(int a, int b) {
	if (is_p(a, b))
		return a;
	if (is_p(b, a))
		return b;
	for (int i = LOG - 1; i >= 0; --i) {
		if (!is_p(up[a][i], b))
			a = up[a][i];
	}
	return up[a][0];
}

int goup(int a, int h) {
	for (int i = LOG - 1; i >= 0; --i) {
		if (h >= (1 << i))
			h -= (1 << i), a = up[a][i];
	}
	return a;
}

hsh geths(const string &s) {
	hsh hs = 0;
	for (int i = 0; i < s.size(); ++i)
		hs = hs * P + s[i];
	return hs;
}

hsh pw[MAXN];
int ans[MAXN];
vector<hsh> vv;
vector<tuple<hsh, int, int>> go[MAXN];

void add(int v, hsh hs, int k, int d) {
	go[v].emplace_back(hs, k, d);
}

int lst[MAXN];
int cc[MAXN];
vector<char> st;

void dfs2(int v, int p) {
	if (v != 0)
		st.push_back(pc[v]);
	vector<pair<int, int>> undo;
	hsh hs = 0;
	for (int i = (int)st.size() - 1; i >= 0 && i >= (int)st.size() - 100; --i) {
		hs = hs * P + st[i];
		int pos = lower_bound(ALL(vv), hs) - vv.begin();
		undo.emplace_back(pos, lst[pos]);
		++cc[pos];
	}

	for (auto q: go[v]) {
		hsh hs; int k, d;
		tie(hs, k, d) = q;
		int pos = lower_bound(ALL(vv), hs) - vv.begin();
		ans[k] += d * cc[pos];
	}
	for (auto e: eds[v]) {
		if (e.first == p)
			continue;
		dfs2(e.first, v);
	}

	for (auto p: undo) {
		--cc[p.first];
		lst[p.first] = p.second;
	}
	if (v != 0)
		st.pop_back();
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	pw[0] = 1;
	for (int i = 1; i < MAXN; ++i)
		pw[i] = (pw[i - 1] * P);
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		char c;
		cin >> a >> b;
		--a, --b;
		cin >> c;
		eds[a].emplace_back(b, c);
		eds[b].emplace_back(a, c);
	}
	dfs1(0, 0);
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> aa[i] >> bb[i];
		--aa[i], --bb[i];
		cin >> s[i];
		int x = lca(aa[i], bb[i]);
		int a = aa[i];
		int b = bb[i];
		int ga = a;
		if (h[a] - h[x] > s[i].size() - 1)
			ga = goup(a, h[a] - h[x] - (s[i].size() - 1));
		int gb = b;
		if (h[b] - h[x] > s[i].size() - 1)
			gb = goup(b, h[b] - h[x] - (s[i].size() - 1));
		string s2;
		string tmp;
		int cur = ga;
		while (cur != x)
			s2 += pc[cur], cur = up[cur][0];
		cur = gb;
		while (cur != x)
			tmp += pc[cur], cur = up[cur][0];
		reverse(ALL(tmp));
		s2 += tmp;
		hsh hs = geths(s[i]);
		if (s2.size() >= s[i].size()) {
			hsh now = 0;
			for (int j = 0; j < s[i].size(); ++j)
				now = now * P + s2[j];
			if (now == hs)
				++ans[i];
			for (int j = s[i].size(); j < s2.size(); ++j) {
				now = now * P + s2[j];
				now -= pw[s[i].size()] * s2[j - s[i].size()];
				if (now == hs)
					++ans[i];
			}
		}
		vv.push_back(hs);
		add(a, hs, i, 1);
		add(ga, hs, i, -1);
		reverse(ALL(s[i]));
		hs = geths(s[i]);
		vv.push_back(hs);
		add(b, hs, i, 1);
		add(gb, hs, i, -1);
	}
	sort(ALL(vv));
	vv.resize(unique(ALL(vv)) - vv.begin());
	for (int i = 0; i < vv.size(); ++i)
		lst[i] = -1, cc[i] = 0;
	dfs2(0, -1);
	for (int i = 0; i < q; ++i)
		cout << ans[i] << "\n";
	return 0;
}


#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

using hsh = ull;
const int MAXN = 120000;
const int LOG = 20;
const hsh P = 23917;

int n;
vector<pair<int, char>> eds[MAXN];
int aa[MAXN];
int bb[MAXN];
string s[MAXN];
int up[MAXN][LOG];
char pc[MAXN];
int tm1;
int tin[MAXN];
int tout[MAXN];
int h[MAXN];

void dfs1(int v, int p) {
	tin[v] = tm1++;
	up[v][0] = p;
	for (int i = 1; i < LOG; ++i)
		up[v][i] = up[up[v][i - 1]][i - 1];
	for (auto e: eds[v]) {
		if (e.first == p)
			continue;
		h[e.first] = h[v] + 1;
		pc[e.first] = e.second;
		dfs1(e.first, v);
	}
	tout[v] = tm1;
}

bool is_p(int a, int b) {
	return tin[a] <= tin[b] && tin[b] < tout[a];
}

int lca(int a, int b) {
	if (is_p(a, b))
		return a;
	if (is_p(b, a))
		return b;
	for (int i = LOG - 1; i >= 0; --i) {
		if (!is_p(up[a][i], b))
			a = up[a][i];
	}
	return up[a][0];
}

int goup(int a, int h) {
	for (int i = LOG - 1; i >= 0; --i) {
		if (h >= (1 << i))
			h -= (1 << i), a = up[a][i];
	}
	return a;
}

hsh geths(const string &s) {
	hsh hs = 0;
	for (int i = 0; i < s.size(); ++i)
		hs = hs * P + s[i];
	return hs;
}

hsh pw[MAXN];
int ans[MAXN];
vector<hsh> vv;
vector<tuple<hsh, int, int>> go[MAXN];

void add(int v, hsh hs, int k, int d) {
	go[v].emplace_back(hs, k, d);
}

int lst[MAXN * 2];
int cc[MAXN * 2];
vector<char> st;

void dfs2(int v, int p) {
	if (v != 0)
		st.push_back(pc[v]);
	vector<pair<int, int>> undo;
	hsh hs = 0;
	for (int i = (int)st.size() - 1; i >= 0 && i >= (int)st.size() - 100; --i) {
		hs = hs * P + st[i];
		int pos = lower_bound(ALL(vv), hs) - vv.begin();
		if (pos == vv.size() || vv[pos] != hs)
			continue;
		undo.emplace_back(pos, lst[pos]);
		++cc[pos];
	}

	for (auto q: go[v]) {
		hsh hs; int k, d;
		tie(hs, k, d) = q;
		int pos = lower_bound(ALL(vv), hs) - vv.begin();
		if (pos == vv.size() || vv[pos] != hs)
			continue;
		ans[k] += d * cc[pos];
	}
	for (auto e: eds[v]) {
		if (e.first == p)
			continue;
		dfs2(e.first, v);
	}

	for (auto p: undo) {
		--cc[p.first];
		lst[p.first] = p.second;
	}
	if (v != 0)
		st.pop_back();
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	pw[0] = 1;
	for (int i = 1; i < MAXN; ++i)
		pw[i] = (pw[i - 1] * P);
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		char c;
		cin >> a >> b;
		--a, --b;
		cin >> c;
		eds[a].emplace_back(b, c);
		eds[b].emplace_back(a, c);
	}
	dfs1(0, 0);
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> aa[i] >> bb[i];
		--aa[i], --bb[i];
		cin >> s[i];
		int x = lca(aa[i], bb[i]);
		int a = aa[i];
		int b = bb[i];
		int ga = a;
		if (h[a] - h[x] > s[i].size() - 1)
			ga = goup(a, h[a] - h[x] - (s[i].size() - 1));
		int gb = b;
		if (h[b] - h[x] > s[i].size() - 1)
			gb = goup(b, h[b] - h[x] - (s[i].size() - 1));
		string s2;
		string tmp;
		int cur = ga;
		while (cur != x)
			s2 += pc[cur], cur = up[cur][0];
		cur = gb;
		while (cur != x)
			tmp += pc[cur], cur = up[cur][0];
		reverse(ALL(tmp));
		s2 += tmp;
		hsh hs = geths(s[i]);
		if (s2.size() >= s[i].size()) {
			hsh now = 0;
			for (int j = 0; j < s[i].size(); ++j)
				now = now * P + s2[j];
			if (now == hs)
				++ans[i];
			for (int j = s[i].size(); j < s2.size(); ++j) {
				now = now * P + s2[j];
				now -= pw[s[i].size()] * s2[j - s[i].size()];
				if (now == hs)
					++ans[i];
			}
		}
		vv.push_back(hs);
		add(a, hs, i, 1);
		add(ga, hs, i, -1);
		reverse(ALL(s[i]));
		hs = geths(s[i]);
		vv.push_back(hs);
		add(b, hs, i, 1);
		add(gb, hs, i, -1);
	}
	sort(ALL(vv));
	vv.resize(unique(ALL(vv)) - vv.begin());
	for (int i = 0; i < vv.size(); ++i)
		lst[i] = -1, cc[i] = 0;
	dfs2(0, -1);
	for (int i = 0; i < q; ++i)
		cout << ans[i] << "\n";
	return 0;
}