#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef int Weight;
struct Edge {
  int src;
  int dest;
  Weight weight;
  Edge(int src, int dest, Weight weight) : src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    return weight > rhs.weight;
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void PrintMatrix(const Matrix &matrix) {
  for (int y = 0; y < (int)matrix.size(); y++) {
    for (int x = 0; x < (int)matrix[y].size(); x++) {
      printf("%d ", matrix[y][x]);
    }
    puts("");
  }
}

bool end[1100];
static const Weight INF = 2000000000LL;
Weight BellmanFord(const Graph &g, Array &dist) {
  const int n = g.size();
  dist = Array(n, 0x0f0f0f0f);
  dist[0] = 0;
  REP(iter, n) {
    bool e = true;
    REP(i, n) {
      REP(j, g[i].size()) {
        int to = g[i][j].dest;
        Weight ncost = dist[i] + g[i][j].weight;
        if (dist[to] > ncost) {
          dist[to] = ncost;
          e = false;
        }
      }
    }
    if (e) { return 0; }
  }
  return -INF;
}

int n, m, k, len;
int color[110];
char ban[1000];
int memo[20][20];

int OneMove(int pattern, int c) {
  if (ban[pattern] == c) { return pattern + 1; }
  if (memo[pattern][c] != -1) { return memo[pattern][c]; }
  deque<int> now;
  REP(i, pattern) { now.push_back(ban[i]); }
  now.push_back(c);
  while (!now.empty()) {
    now.pop_front();
    REP(i, now.size()) {
      if (now[i] != ban[i]) { goto next; }
    }
    break;
next:;
  }
  return memo[pattern][c] = now.size();
}

Graph Expand(Graph g) {
  MEMSET(memo, -1);
  vector<bool> visit(n * len, false);
  queue<pair<int, int> > que;
  int first = color[0] == ban[0] ? 1 : 0;
  que.push(make_pair(0, first));
  Graph ret(n * len);
  if (len == first) { return ret; }
  while (!que.empty()) {
    int from = que.front().first;
    int pattern = que.front().second;
    que.pop();
    if (visit[from * len + pattern]) { continue; }
    visit[from * len + pattern] = true;
    FORIT(it, g[from]) {
      int to = it->dest;
      int c = color[to];
      int npattern = OneMove(pattern, c);
      if (npattern == len) { continue; }
      ret[from * len + pattern].push_back(Edge(from * len + pattern, to * len + npattern, it->weight));
      que.push(make_pair(to, npattern));
    }
  }
  return ret;
}

Graph revG(Graph g) {
  Graph ret(g.size());
  REP(i, g.size()) {
    FORIT(it, g[i]) {
      ret[it->dest].push_back(Edge(it->dest, it->src, it->weight));
    }
  }
  return ret;
}

void dfs(const Graph &g, int from, vector<bool> &visit) {
  if (visit[from]) { return; }
  visit[from] = true;
  FORIT(it, g[from]) {
    dfs(g, it->dest, visit);
  }
}

Graph Erase(Graph g) {
  MEMSET(end, false);
  vector<bool> visit1(1010, 0);
  vector<bool> visit2(1010, 0);
  Graph rev = revG(g);
  dfs(g, color[0] == ban[0], visit1);
  if (len == 1 && color[0] == ban[0]) { visit1[1] = false; }
  REP(i, len) { dfs(rev, (n - 1) * len + i, visit2); }
  int m = 0;
  map<int, int> mapto;
  REP(i, n * len) {
    if (!visit1[i] || !visit2[i]) { continue; }
    if (i >= (n - 1) * len) { end[m] = true; }
    mapto[i] = m++;
  }
  Graph ret(m);
  REP(i, n * len) {
    if (!mapto.count(i)) { continue; }
    int from = mapto[i];
    FORIT(it, g[i]) {
      if (!mapto.count(it->dest)) { continue; }
      int to = mapto[it->dest];
      ret[from].push_back(Edge(from, to, it->weight));
    }
  }
  return ret;
}

vector<int> dists[1010];
pair<int, int> calc(const Graph &g) {
  if (g.size() == 0) { return make_pair(0, 0); }
  Array dist;
  int v = BellmanFord(g, dist);
  if (v == -INF) { return make_pair(-1, -1); }
  priority_queue<Edge> que;
  que.push(Edge(0, 0, 0));
  REP(i, 1010) { dists[i].clear(); }
  vector<int> ans;
  while (!que.empty()) {
    Edge e = que.top();
    que.pop();
    int from = e.dest;
    if ((int)dists[from].size() == k) { continue; }
    dists[from].push_back(e.weight);
    if (end[from]) { ans.push_back(e.weight + dist[from]); }
    FORIT(it, g[from]) {
      int to = it->dest;
      int ncost = it->weight + e.weight + (dist[from] - dist[to]);
      que.push(Edge(from, to, ncost));
    }
  }
  pair<int, int> ret = make_pair(0, 0);
  sort(ans.begin(), ans.end());
  ret.first = min(k, (int)ans.size());
  REP(i, ret.first) { ret.second += ans[i]; }
  return ret;
}

int main() {
  while (scanf("%d", &n), n) {
    REP(i, n) { scanf("%d", &color[i]); }
    scanf("%d", &m);
    Graph g(n);
    REP(i, m) {
      int f, t, c;
      scanf("%d %d %d", &f, &t, &c);
      f--; t--;
      g[f].push_back(Edge(f, t, c));
    }
    scanf("%d", &k);
    scanf("%s", ban);
    len = strlen(ban);
    REP(i, len) { ban[i] -= '0'; }
    g = Expand(g);
    g = Erase(g);
    pair<int, int> ans = calc(g);
    if (ans.first == -1) {
      puts("-1");
    } else {
      printf("%d %d\n", ans.first, ans.second);
    }
  }
}

Measured memory_bytes: 1948