Problem: The University of Aizu Elementary School (Aizu University and Small) is famous as one of Japan's leading competition programmer training schools. Of course, it is essential to practice the algorithm even when attending an athletic meet.

Of course you, the director of the competitive programming department, want to win this tournament as well. This time we will focus on a certain competition.

A certain competition is a traditional competition held in Aizu, large and small. There are n cones in the schoolyard. Four colors of corn are available. Several pairs of cones are connected by arrows drawn with white lines. The arrow is attached to only one side, and an integer is also written.

Athletes act as a team of k people. Move in that direction from the cone at the starting point to the cone at the goal point on the arrow. However, each k person needs to have a different route to the goal point.

The fact that route 1 and route 2 are different means that

* Condition 1 If the number of arrows that pass through Route 1 and Route 2 is the same, there must be an i that has a different arrow that goes through the i-th in Route 1 and the arrow that goes through in the i-th in Route 2.
* Condition 2 The number of arrows passing through Route 1 and Route 2 is different.



It can be said that the route is different if any of the above is satisfied.

In addition, there is a prohibited color pattern in how to follow the cone, and players who include that pattern on the route from the start point to the goal point will be retired. However, other routes may follow any route, and may pass through the same cone (including the cone at the start point and the goal point) many times. In addition, the numbers written along with the arrows are added as scores. The competition is won by the team with more teammates reaching the goal cone with a smaller total score.

You, the director, should of course be able to solve this problem with programming. Find the maximum number of people who can move to the goal. Also, find the minimum score when you reach the maximum number of people.

However, if you can reduce the score as much as you want, output -1.



Input

The input consists of multiple test cases. The number of test cases does not exceed 20.


n
col1
col2
...
coln
m
a1 b1 c1
a2 b2 c2
...
am bm cm
k
pattern


n (2 ≤ n ≤ 100) represents the number of cones. coli (1 ≤ coli ≤ 4) indicates the color of the i-th cone. m (0 ≤ m ≤ 1,000) represents the number of arrows. ai is the number of the cone at the start of the arrow, bi is the number of the cone at the end, and ci is the score of the arrow. Also, up to 10 arrows can extend from one cone. (1 ≤ ai, bi ≤ n, -1,000 ≤ ci ≤ 1,000) k indicates the number of teams competing. (1 ≤ k ≤ 10) pattern is a character string consisting of numbers 1 to 4 with a length of 10 or less, and indicates a pattern in which movement is prohibited. The starting cone is the first cone and the nth cone is the goal. The numbers given in the input (n, col, m, a, b, c, k) are all integers. The end of the input is indicated by one line containing 0.

Output

The output consists of two integers separated by blanks. The first is the number of people that can be reached, and the second is its minimum cost. If you can reduce the score as much as you want, output one line containing only -1. If no one can reach it, output 0 0.

Example

Input

2
1
1
2
1 2 1
2 1 1
1
1111
2
1
1
2
1 2 1
2 1 1
1
11
2
1
1
2
1 2 1
2 1 1
10
1111
2
1
1
2
1 2 1
2 1 1
10
111111
2
1
1
2
1 2 -1
2 1 0
10
11
2
1
1
2
1 2 -1
2 1 0
10
1111
2
1
1
2
1 2 -1
2 1 0
10
12
2
1
1
2
1 2 -1
2 1 0
10
1111111111
0


Output

1 1
0 0
1 1
2 4
0 0
1 -1
-1
4 -10

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< vector<pii> > graph;

const int INF = 1e9;

inline int match(int cur, int in, const string &s){
  string prv = s.substr(0,cur) + (char)(in+'0');
  rep(i,cur+1){
    int len = cur+1-i;
    if(s.substr(0,len) == prv.substr(i,len))return len;
  }
  return 0;
}

void dfs(int cur, vector<int> &vis, graph &g){
  if(vis[cur])return;
  vis[cur] = 1;
  for(pii e : g[cur])dfs(e.second, vis, g);
}

bool BellmanFord(int s, int V, vector<int> &d, const graph &g){
  d = vi(V,INF);
  d[s] = 0;
  rep(azu,V){
    bool f = false;
    rep(i,V)for(pii e : g[i]){
      if(d[i]<INF && d[e.second] > d[i] + e.first){
	d[e.second] = d[i] + e.first;
	f = true;
      }
    }
    if(!f)return true;
  }
  return false;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);

  int n,m,k,l;
  string pattern;
  while(cin >> n, n){
    vi col(n);
    rep(i,n)cin >> col[i], col[i]--;
    cin >> m;
    graph base(n);
    rep(i,m){
      int a,b,c;
      cin >> a >> b >> c; a--; b--;
      base[a].push_back(pii(c,b));
    }    
    cin >> k >> pattern;
    l = pattern.size();

    vector<vi> trans(l, vi(4,0));
    rep(i,l)rep(j,4){
      trans[i][j] = match(i,j+1,pattern);
    }

    int V = n*l;
    graph g(V), rg(V);
    rep(i,l)rep(j,n){
      for(pii e : base[j]){
	int to = e.second, nxt = trans[i][col[to]];
	if(nxt == l)continue;
	g[i*n+j].push_back(pii(e.first, nxt*n+to));
	rg[nxt*n+to].push_back(pii(e.first, i*n+j));
      }
    }

    if(trans[0][col[0]] == l){
      cout << "0 0" << endl;
      continue;
    }

    int S = trans[0][col[0]]*n;
    vi vis(V,0), rvis(V,0);
    dfs(S,vis,g);
    rep(i,l)dfs(i*n+n-1,rvis,rg);

    rep(i,V){
      if(vis[i]==0 || rvis[i]==0)g[i].clear();
      rep(j,g[i].size()){
	int to = g[i][j].second;
	if(vis[to]==0 || rvis[to]==0){
	  g[i].erase(g[i].begin()+j);
	  j--;
	}
      }
    }
    

    vi h;
    if(!BellmanFord(S, V, h, g)){
      cout << -1 << endl;
      continue;
    }

    vector< vi > d(V, vi(k,INF));
    d[S][0] = 0;
    priority_queue< pii, vector<pii>, greater<pii> > q;
    q.push(pii(0,S));

    while(q.size()){
      pii p = q.top(); q.pop();
      int v = p.second, c = p.first;

      for(pii e : g[v]){
	int nv = e.second, nc = c + e.first + h[v] - h[nv];
	bool f = true;
	rep(i,k){
	  if(d[nv][i] > nc){
	    if(f)q.push(pii(nc,nv)), f=false;
	    swap(d[nv][i],nc);
	  }
	}
      }
    }
	    
    vi can;
    rep(i,l)rep(j,k){
      if(d[i*n+n-1][j]!=INF){
	can.push_back(d[i*n+n-1][j] - h[S] + h[i*n+n-1]);
      }
    }
    sort(can.begin(),can.end());

    int ans = min((int)can.size(),k);
    long long sum = 0;
    rep(i,ans)sum += can[i];
    cout << ans << " " << sum << endl;
  }
}