#include <bits/stdc++.h>
using namespace std;
const int MINUTES_PER_DAY = 60 * 24, N = 110, TOTAL = N * MINUTES_PER_DAY;
struct Query {
  int t, p, r, id;
};
map<string, int> T;
vector<string> subjects;
bool can[TOTAL], chosen[TOTAL][N];
vector<pair<int, int>> busy;
int init[N][TOTAL], pay[N], dp[TOTAL][N], arr[N];
vector<Query> vet;
stack<Query> ans;
void back(int i, int j) {
  while (j) {
    if (chosen[i][j]) {
      ans.push({arr[j], init[j][i], i});
      if (!init[j][i]) break;
      i = init[j][i];
      j--;
    } else if (i and dp[i - 1][j] > dp[i][j - 1])
      i--;
    else
      j--;
  }
  printf("%d\n", (int)ans.size());
  while (!ans.empty()) {
    Query x = ans.top();
    ans.pop();
    int id = x.t, t1 = x.p, t2 = x.r;
    int d1 = t1 / MINUTES_PER_DAY, h1 = t1 % MINUTES_PER_DAY / 60, m1 = t1 % 60;
    int d2 = t2 / MINUTES_PER_DAY, h2 = t2 % MINUTES_PER_DAY / 60, m2 = t2 % 60;
    printf("%d %d %02d:%02d %d %02d:%02d\n", id, d1, h1, m1, d2, h2, m2);
  }
}
int main() {
  int m, n, k;
  cin >> m >> n >> k;
  subjects.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> subjects[i];
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    T[subjects[i]] = x;
  }
  for (int i = 0; i < 4; i++) {
    string str;
    cin >> str;
    int h1, m1, h2, m2;
    sscanf(str.c_str(), "%d:%d-%d:%d", &h1, &m1, &h2, &m2);
    int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2;
    if (t1 <= t2)
      busy.push_back({t1, t2});
    else {
      busy.push_back({t1, MINUTES_PER_DAY - 1});
      busy.push_back({0, t2});
    }
  }
  for (int i = 1; i <= k; i++)
    for (int j = 0; j < MINUTES_PER_DAY; j++) {
      bool valid = true;
      for (auto it : busy)
        if (j >= it.first and j <= it.second) valid = false;
      can[i * MINUTES_PER_DAY + j] = valid;
    }
  memset(init, -1, sizeof(init));
  for (int i = 1; i <= n; i++) {
    string str, aux;
    int d, h, m;
    cin >> str >> d >> aux >> pay[i];
    sscanf(aux.c_str(), "%d:%d", &h, &m);
    if (T.find(str) == T.end()) continue;
    int t = -T[str];
    d = d * MINUTES_PER_DAY + h * 60 + m;
    vet.push_back({d, pay[i], t, i});
  }
  sort(vet.begin(), vet.end(), [](Query i, Query j) { return i.t < j.t; });
  n = (int)vet.size();
  for (int i = 0; i < n; i++) {
    int t = vet[i].r, d = vet[i].t, f = 0;
    while (f < d and !can[f]) f++;
    int j = f;
    pay[i + 1] = vet[i].p;
    arr[i + 1] = vet[i].id;
    for (; j < d; j++) {
      t += can[j];
      while (t > 0) t -= can[f++];
      while (f < d and !can[f]) f++;
      if (!t) {
        init[i + 1][j] = f;
      }
    }
  }
  for (int i = 0; i < TOTAL; i++)
    for (int j = 1; j <= n; j++) {
      dp[i][j] = dp[i][j - 1];
      if (i and dp[i - 1][j] > dp[i][j]) dp[i][j] = dp[i - 1][j];
      if (init[j][i] != -1) {
        int x = pay[j] + (init[j][i] ? dp[init[j][i] - 1][j - 1] : 0);
        if (dp[i][j] < x) {
          dp[i][j] = x;
          chosen[i][j] = true;
        }
      }
    }
  printf("%d\n", dp[TOTAL - 1][n]);
  back(TOTAL - 1, n);
  return 0;
}
