#include <bits/stdc++.h>
using namespace std;
map<string, int> isase;
struct info {
  string s;
  int d, h, m, c, f, id;
} help[101];
struct info_time {
  int h, m, d;
} ar[100000], a[4][2];
struct info_ans {
  int id, s, e;
} o;
vector<info_ans> vec;
int t, n, m;
bool fun(int i, int h, int m) {
  int s, e, md;
  md = h * 60 + m;
  s = a[i][0].h * 60 + a[i][0].m;
  e = a[i][1].h * 60 + a[i][1].m;
  if (md >= s && md <= e) return 0;
  return 1;
}
int dp[102][50000];
int go(int h, int m) {
  if (h >= n) {
    dp[h][m] = 0;
    return 0;
  }
  if (m >= t) {
    dp[h][m] = 0;
    return 0;
  }
  if (dp[h][m] != -1) return dp[h][m];
  int c1 = 0, c2 = 0, v;
  v = isase[help[h].s];
  if (v != 0 && m + v - 1 <= help[h].f && help[h].f != -1) {
    c1 = help[h].c + go(h + 1, m + v);
  }
  c2 = go(h + 1, m);
  return dp[h][m] = max(c1, c2);
}
void call(int h, int m) {
  if (h >= n) {
    return;
  }
  if (m >= t) {
    return;
  }
  int c1 = 0, c2 = 0, v;
  v = isase[help[h].s];
  if (v != 0 && m + v - 1 <= help[h].f && help[h].f != -1) {
    c1 = help[h].c + dp[h + 1][m + v];
  }
  c2 = dp[h + 1][m];
  if (c1 > c2) {
    o.id = h;
    o.s = m;
    o.e = m + v - 1;
    vec.push_back(o);
    call(h + 1, m + v);
  } else {
    call(h + 1, m);
  }
  return;
}
bool comp(info x, info y) { return x.f < y.f; }
int main() {
  string s[101];
  int d, i, j, l, k;
  scanf("%d%d%d", &m, &n, &d);
  for (i = 0; i < m; i++) cin >> s[i];
  for (i = 0; i < m; i++) {
    scanf("%d", &t);
    isase[s[i]] = t;
  }
  for (i = 0; i < 4; i++)
    scanf("%d:%d-%d:%d", &a[i][0].h, &a[i][0].m, &a[i][1].h, &a[i][1].m);
  t = 0;
  for (i = 1; i <= d; i++) {
    for (j = 0; j < 24; j++)
      for (k = 0; k < 60; k++) {
        if (fun(0, j, k) && fun(1, j, k) && fun(2, j, k) && fun(3, j, k)) {
          ar[t].h = j;
          ar[t].m = k;
          ar[t].d = i;
          t++;
        }
      }
  }
  for (i = 0; i < n; i++) {
    help[i].id = i;
    cin >> help[i].s;
    scanf("%d %d:%d %d", &help[i].d, &help[i].h, &help[i].m, &help[i].c);
    help[i].f = -1;
    for (j = 0; j < t; j++)
      if (ar[j].d < help[i].d) {
        help[i].f = j;
      } else if (ar[j].d == help[i].d) {
        int e, m;
        m = ar[j].h * 60 + ar[j].m;
        e = help[i].h * 60 + help[i].m;
        if (m < e) help[i].f = j;
      }
  }
  sort(help, help + n, comp);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", go(0, 0));
  call(0, 0);
  j = vec.size();
  printf("%d\n", j);
  for (i = 0; i < j; i++) {
    printf("%d %d ", help[vec[i].id].id + 1, ar[vec[i].s].d);
    if (ar[vec[i].s].h < 10)
      printf("0%d:", ar[vec[i].s].h);
    else
      printf("%d:", ar[vec[i].s].h);
    if (ar[vec[i].s].m < 10)
      printf("0%d", ar[vec[i].s].m);
    else
      printf("%d", ar[vec[i].s].m);
    printf(" %d ", ar[vec[i].e].d);
    if (ar[vec[i].e].h < 10)
      printf("0%d:", ar[vec[i].e].h);
    else
      printf("%d:", ar[vec[i].e].h);
    if (ar[vec[i].e].m < 10)
      printf("0%d\n", ar[vec[i].e].m);
    else
      printf("%d\n", ar[vec[i].e].m);
  }
}
