#include <bits/stdc++.h>
using namespace std;
char a[100][40];
char b[100][40];
int at[1445], use[100], ok[100], idx[100], pos[100], sum[100], cnt;
int dp[43205], ans_dd, ans_hh, ans_mm;
int pt[43205][100];
void run_to(int t) {
  while (1) {
    int next_dd = ans_dd;
    int next_hh = ans_hh;
    int next_mm = ans_mm;
    if (++next_mm == 60) {
      next_mm = 0;
      if (++next_hh == 24) {
        next_hh = 0;
        next_dd++;
      }
    }
    if ((next_dd - 1) * cnt + at[next_hh * 60 + next_mm] >= t) break;
    ans_dd = next_dd;
    ans_hh = next_hh;
    ans_mm = next_mm;
  }
}
void output(int t, int i, int cnt) {
  if (~i) {
    int x = pt[t][i];
    if (~x) {
      output(t - use[idx[x]], i - 1, cnt + 1);
      run_to(t - use[idx[x]] + 1);
      printf("%d %d %02d:%02d", x + 1, ans_dd, ans_hh, ans_mm);
      run_to(t);
      printf(" %d %02d:%02d\n", ans_dd, ans_hh, ans_mm);
    } else {
      output(t, i - 1, cnt);
    }
  } else {
    printf("%d\n", cnt);
  }
}
int main() {
  int m, n, all, hh, mm;
  scanf("%d%d%d", &m, &n, &all);
  for (int i = 0; i < m; i++) scanf("%s", a[i]);
  for (int i = 0; i < m; i++) scanf("%d", use + i);
  for (int i = 0; i < 4; i++) {
    scanf("%d:%d-", &hh, &mm);
    int st = hh * 60 + mm;
    scanf("%d:%d", &hh, &mm);
    int ed = hh * 60 + mm;
    for (int x = st; x <= ed; x++) at[x] = -1;
  }
  for (int x = 0; x < 1440; x++)
    if (~at[x]) at[x] = cnt++;
  all *= at[1440] = cnt;
  for (int x = 1439; ~x; x--)
    if (at[x] < 0) at[x] = at[x + 1];
  for (int i = 0; i < n; i++) {
    scanf("%s", b[i]);
    for (idx[i] = 0; idx[i] < m; idx[i]++)
      if (!strcmp(b[i], a[idx[i]])) break;
    if (idx[i] != m) ok[i] = 1;
    scanf("%d%d:%d%d", pos + i, &hh, &mm, sum + i);
    pos[i] = (pos[i] - 1) * cnt + at[hh * 60 + mm];
  }
  for (int i = 0; i < n; i++) {
    int k = -1;
    for (int j = 0; j < n; j++)
      if (ok[j] && (k < 0 || pos[j] < pos[k])) k = j;
    for (int x = all; ~x; x--) pt[x][i] = -1;
    for (int x = all; ~x; x--) {
      int t = x + use[idx[k]];
      if (t <= pos[k] && sum[k] + dp[x] > dp[t]) {
        dp[t] = sum[k] + dp[x];
        pt[t][i] = k;
      }
    }
    ok[k] = 0;
  }
  int x = max_element(dp, dp + all + 1) - dp;
  printf("%d\n", dp[x]);
  output(x, n - 1, 0);
}
