#include <bits/stdc++.h>
int min(int a, int b) { return a < b ? a : b; }
int idx(char ss[][64], int n, char *s) {
  int i;
  for (i = 0; i < n; i++)
    if (strcmp(ss[i], s) == 0) return i;
  return -1;
}
int bl[4], br[4], d;
int real2imag(int g, int t) {
  int h, t_;
  for (h = 0; h < 4; h++)
    if (bl[h] <= t && t <= br[h]) {
      while (1) {
        if (h == 0 && bl[0] == 0) g--;
        if (h > 0 && bl[h] - br[h - 1] > 1 ||
            h == 0 && (bl[0] > 0 || br[3] < 1440 - 1)) {
          t = h == 0 && bl[0] == 0 ? 1440 - 1 : bl[h] - 1;
          break;
        }
        h = (h - 1 + 4) % 4;
      }
      break;
    }
  if (g < 0) return -1;
  t_ = g * d + t;
  for (h = 0; h < 4; h++)
    if (br[h] < t) t_ -= br[h] - bl[h] + 1;
  return t_;
}
int imag2real(int t_) {
  int g, h;
  g = t_ / d;
  t_ %= d;
  for (h = 0; h < 4; h++)
    if (t_ >= bl[h]) t_ += br[h] - bl[h] + 1;
  return g * 1440 + t_;
}
int ll[100], rr[100];
int compare(const void *a, const void *b) {
  int h1 = *(int *)a;
  int h2 = *(int *)b;
  return rr[h2] - rr[h1];
}
int main() {
  static char ss[100][64];
  static int len[100], cc[100], hh[100], dp[100 + 1][(30 * 1440) + 1],
      pp[100 + 1][(30 * 1440) + 1], qu[100], ll_[100], rr_[100];
  int n, m, k, h, i, t, t_, cnt;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 0; i < n; i++) scanf("%s", ss[i]);
  for (i = 0; i < n; i++) scanf("%d", &len[i]);
  d = 1440;
  for (h = 0; h < 4; h++) {
    int hrl, mnl, hrr, mnr;
    scanf("%d:%d-%d:%d", &hrl, &mnl, &hrr, &mnr);
    bl[h] = hrl * 60 + mnl, br[h] = hrr * 60 + mnr;
    d -= br[h] - bl[h] + 1;
  }
  if (d == 0) {
    printf("0\n");
    printf("0\n");
    return 0;
  }
  for (h = 0; h < m; h++) {
    static char s[64];
    int g, hr, mn;
    scanf("%s%d%d:%d%d", s, &g, &hr, &mn, &cc[h]), g--;
    if (mn > 0)
      mn--;
    else if (hr > 0)
      hr--, mn = 59;
    else
      g--, hr = 23, mn = 59;
    if ((i = idx(ss, n, s)) != -1)
      rr[h] = real2imag(g, hr * 60 + mn), ll[h] = rr[h] - len[i] + 1;
    else
      ll[h] = rr[h] = -1;
    hh[h] = h;
  }
  qsort(hh, m, sizeof *hh, compare);
  for (h = 0; h <= m; h++) memset(dp[h], -1, sizeof dp[h]);
  dp[0][(30 * 1440)] = 0;
  for (h = 0; h < m; h++) {
    int h_ = hh[h];
    for (t = 0; t <= (30 * 1440); t++) {
      int x = dp[h][t];
      if (x == -1) continue;
      t_ = t;
      if (t_ >= 0 && dp[h + 1][t_] < x) dp[h + 1][t_] = x, pp[h + 1][t_] = t;
      t_ = min(t, rr[h_] + 1) - (rr[h_] - ll[h_] + 1);
      x += cc[h_];
      if (t_ >= 0 && dp[h + 1][t_] < x) dp[h + 1][t_] = x, pp[h + 1][t_] = t;
    }
  }
  t_ = 0;
  for (t = 1; t <= (30 * 1440); t++)
    if (dp[m][t_] < dp[m][t]) t_ = t;
  cnt = 0;
  for (h = m, t = t_; h > 0; h--)
    if (t != pp[h][t]) {
      int p = pp[h][t], h_ = hh[h - 1];
      qu[cnt] = h_, rr_[cnt] = min(p, rr[h_] + 1) - 1,
      ll_[cnt] = rr_[cnt] - (rr[h_] - ll[h_]), cnt++;
      t = p;
    }
  printf("%d\n", dp[m][t_]);
  printf("%d\n", cnt);
  for (h = 0; h < cnt; h++) {
    int l = imag2real(ll_[h]), r = imag2real(rr_[h]);
    printf("%d %d %02d:%02d %d %02d:%02d\n", qu[h] + 1, l / 1440 + 1,
           l % 1440 / 60, l % 1440 % 60, r / 1440 + 1, r % 1440 / 60,
           r % 1440 % 60);
  }
  return 0;
}
