#include <bits/stdc++.h>
using namespace std;
int M, N, K;
map<string, int> msi;
char cs[161][161];
int tsum[(31 * 24 * 60 + 100)];
int Tm[(31 * 24 * 60 + 100)];
int uset[161];
int edt[161];
int money[161];
int tid[161];
int dp[161][(31 * 24 * 60 + 100)];
int pre[161][(31 * 24 * 60 + 100)];
void outtime(int t) {
  int day = t / (24 * 60) + 1;
  int m = t / 60 % 24;
  int s = t % 60;
  printf("%d %02d:%02d", day, m, s);
}
void print(int idx, int t) {
  if (idx == 0) return;
  print(idx - 1, pre[idx][t]);
  if (pre[idx][t] != t) {
    printf("%d ", tid[idx]);
    outtime(Tm[pre[idx][t] + 1]);
    printf(" ");
    outtime(Tm[t]);
    printf("\n");
  }
}
int main() {
  scanf("%d%d%d", &M, &N, &K);
  for (int i = (0); i < (M); i++) scanf("%s", cs[i]);
  for (int i = (0); i < (M); i++) {
    int v;
    scanf("%d", &v);
    msi[string(cs[i])] = v;
  }
  memset((tsum), 0, sizeof(tsum));
  for (int i = (0); i < ((31 * 24 * 60 + 100)); i++) tsum[i] = 1;
  for (int i = (0); i < (4); i++) {
    int a, b, c, d;
    scanf("%d:%d-%d:%d", &a, &b, &c, &d);
    int bg = a * 60 + b, ed = c * 60 + d;
    for (int j = 0;; j++) {
      int offset = j * 24 * 60;
      bool f = false;
      for (int k = (offset + bg); k < (offset + ed + 1); k++) {
        if (k >= (31 * 24 * 60 + 100)) {
          f = true;
          break;
        }
        tsum[k] = 0;
      }
      if (f) break;
    }
  }
  for (int i = (1); i < ((31 * 24 * 60 + 100)); i++) tsum[i] += tsum[i - 1];
  memset(Tm, 0x7f, sizeof Tm);
  for (int i = (((31 * 24 * 60 + 100)) - 1); i >= (0); i--) Tm[tsum[i]] = i;
  for (int i = (1); i < (N + 1); i++) {
    char name[161];
    int a, b, c, m;
    scanf("%s%d%d:%d%d", name, &a, &b, &c, &m);
    tid[i] = i;
    if (msi.count(string(name)) > 0)
      uset[i] = msi[string(name)], edt[i] = ((a - 1) * 24 + b) * 60 + c;
    else
      edt[i] = -1;
    money[i] = m;
  }
  for (int i = (1); i < (N + 1); i++)
    for (int j = (i + 1); j < (N + 1); j++)
      if (edt[i] > edt[j]) {
        swap(edt[i], edt[j]);
        swap(uset[i], uset[j]);
        swap(money[i], money[j]);
        swap(tid[i], tid[j]);
      }
  memset((pre), 0, sizeof(pre));
  memset(dp, 0xff, sizeof dp);
  dp[0][0] = 0;
  for (int i = (0); i < (N); i++) {
    for (int j = (0); j < ((31 * 24 * 60 + 100)); j++)
      if (dp[i][j] >= 0) {
        if (dp[i + 1][j] < dp[i][j]) dp[i + 1][j] = dp[i][j], pre[i + 1][j] = j;
        if (edt[i + 1] == -1) continue;
        int nj = j + uset[i + 1];
        if (nj >= (31 * 24 * 60 + 100) || Tm[nj] >= edt[i + 1]) continue;
        if (dp[i + 1][nj] < dp[i][j] + money[i + 1])
          dp[i + 1][nj] = dp[i][j] + money[i + 1], pre[i + 1][nj] = j;
      }
  }
  int ret = -1, maxi = -1;
  for (int i = (0); i < ((31 * 24 * 60 + 100)); i++)
    if (dp[N][i] > ret) ret = dp[N][i], maxi = i;
  int cnt = 0;
  int j = maxi;
  for (int i = ((N + 1) - 1); i >= (0); i--)
    if (pre[i][j] != j) cnt++, j = pre[i][j];
  printf("%d\n%d\n", ret, cnt);
  print(N, maxi);
  return 0;
}
