#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

struct edge{ int v,cost; };

struct Xnode{
	int u,t;
	bool operator<(const Xnode &X)const{ return u<X.u || u==X.u && t<X.t; }
};

struct Xedge{
	Xnode X;
	int cost;
};

int n,color[100],K,len;
vector<edge> G[100];
char pttn[11];

bool input(){
	scanf("%d",&n);
	if(n==0) return false;
	rep(u,n){
		G[u].clear();
		scanf("%d",color+u);
	}
	int m; scanf("%d",&m);
	rep(i,m){
		int u,v,cost; scanf("%d%d%d",&u,&v,&cost); u--; v--;
		G[u].push_back((edge){v,cost});
	}
	scanf("%d%s",&K,pttn);
	len=strlen(pttn);
	return true;
}

vector<Xedge> XG[100][10],XG_rev[101][10];
void build_XG(){
	rep(u,n+1) rep(t,max(len,2)) {
		XG[u][t].clear();
		XG_rev[u][t].clear();
	}

	rep(u,n) rep(t,len) rep(i,G[u].size()) {
		int v=G[u][i].v,cost=G[u][i].cost;

		char tmp[12]={};
		strncpy(tmp,pttn,t);
		tmp[t]=color[v]+'0';
		int t_next;
		for(t_next=t+1;strncmp(pttn,tmp+(t+1)-t_next,t_next);t_next--);

		if(t_next<len){
			XG[u][t].push_back((Xedge){(Xnode){v,t_next},cost});
			XG_rev[v][t_next].push_back((Xedge){(Xnode){u,t},cost});
		}
	}
	rep(t,len) XG_rev[n][0].push_back((Xedge){(Xnode){n-1,t},0});
}

bool vis[101][10];
bool dfs(int u,int t){
	vis[u][t]=true;
	rep(i,XG[u][t].size()){
		const Xedge &e=XG[u][t][i];
		int v=e.X.u,t_next=e.X.t;
		if(!vis[v][t_next]) dfs(v,t_next);
	}
}

bool vis_rev[101][10];
bool dfs_rev(int v,int t){
	vis_rev[v][t]=true;
	rep(i,XG_rev[v][t].size()){
		const Xedge &e=XG_rev[v][t][i];
		int u=e.X.u,t_prev=e.X.t;
		if(!vis_rev[u][t_prev]) dfs_rev(u,t_prev);
	}
}

void delete_Xnodes(){
	rep(u,n+1) rep(t,len) vis[u][t]=vis_rev[u][t]=false;

	int t0=(pttn[0]==color[0]+'0'?1:0);
	dfs(0,t0);
	dfs_rev(n,0);

	rep(u,n) rep(t,len) {
		if(!vis[u][t] || !vis_rev[u][t]){
			XG[u][t].clear();
		}
		else{
			rep(i,XG[u][t].size()){
				const Xedge &e=XG[u][t][i];
				int v=e.X.u,t_next=e.X.t;
				if(!vis[v][t_next] || !vis_rev[v][t_next]){
					XG[u][t].erase(XG[u][t].begin()+i);
					i--;
				}
			}
		}
	}
}

int pot[101][10];
bool calc_potential(){
	rep(u,n+1) rep(t,len) pot[u][t]=0;

	rep(c,n*len){
		rep(u,n+1) rep(t,len) rep(i,XG[u][t].size()) {
			const Xedge &e=XG[u][t][i];
			int v=e.X.u,t_next=e.X.t,cost=e.cost;
			if(pot[u][t]+cost<pot[v][t_next]){
				pot[v][t_next]=pot[u][t]+cost;
				if(c==n*len-1){
					puts("-1");
					return false;
				}
			}
		}
	}
	return true;
}

void Kth_shortest_path(){
	int nd[100][10]={},d[100][10][10];
	int t0=(pttn[0]==color[0]+'0'?1:0);

	priority_queue< pair<int,Xnode> > Q;
	Q.push(make_pair(0,(Xnode){0,t0}));
	while(!Q.empty()){
		int d_now=-Q.top().first;
		int u=Q.top().second.u,t=Q.top().second.t; Q.pop();

		if(nd[u][t]==K) continue;
		d[u][t][nd[u][t]++]=d_now;

		rep(i,XG[u][t].size()){
			const Xedge &e=XG[u][t][i];
			int v=e.X.u,t_next=e.X.t,cost=e.cost;
			if(nd[v][t_next]<K){
				int d_next=d_now+cost+pot[u][t]-pot[v][t_next];
				Q.push(make_pair(-d_next,(Xnode){v,t_next}));
			}
		}
	}

	vector<int> ans;
	rep(t,len) rep(i,nd[n-1][t]) ans.push_back(d[n-1][t][i]-pot[0][t0]+pot[n-1][t]);
	sort(ans.begin(),ans.end());

	int n_ans=min((int)ans.size(),K),ans_sum=0;
	rep(i,n_ans) ans_sum+=ans[i];
	printf("%d %d\n",n_ans,ans_sum);
}

int main(){
	while(input()){
		build_XG();
		delete_Xnodes();
		if(!calc_potential()) continue;
		Kth_shortest_path();
	}
	return 0;
}

Measured memory_bytes: 2196