#include <bits/stdc++.h>
using namespace std;
int A[30 * 24 * 60 + 1];
int B[30 * 24 * 60 + 1];
string ToTime(int a) {
  ostringstream ostr;
  a = B[a];
  ostr << a / (24 * 60) + 1 << " ";
  a %= 24 * 60;
  ostr << a / 60 / 10 << a / 60 % 10 << ":";
  a %= 60;
  ostr << a / 10 << a % 10;
  return ostr.str();
}
bool rest[24 * 60];
array<int, 3> dp[30 * 24 * 60 + 1][101];
int main() {
  vector<string> subject;
  map<string, int> times;
  int m, n, k;
  cin >> m >> n >> k;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    subject.push_back(s);
  }
  for (int i = 0; i < m; i++) {
    cin >> times[subject[i]];
  }
  for (int i = 0; i < 4; i++) {
    int h0, m0, h1, m1;
    char c;
    cin >> h0 >> c >> m0 >> c >> h1 >> c >> m1;
    for (int j = h0; j <= h1; j++) {
      for (int k = ((j == h0) ? m0 : 0); k <= ((j == h1) ? m1 : 59); k++) {
        rest[j * 60 + k] = true;
      }
    }
  }
  int total;
  {
    int c = 0, d = 0;
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 24; j++) {
        for (int k = 0; k < 60; k++) {
          if (!rest[j * 60 + k]) {
            c++;
            B[c] = d;
          }
          A[d] = c;
          d++;
        }
      }
    }
    total = c + 1;
  }
  vector<array<int, 4> > ts;
  for (int i = 0; i < n; i++) {
    string s;
    int d, h, m, v;
    char c;
    cin >> s >> d >> h >> c >> m >> v;
    int t = ((d - 1) * 24 + h) * 60 + m - 1;
    if (times.count(s) == 0) continue;
    ts.push_back({{A[t], times[s], v, i + 1}});
  }
  sort(ts.begin(), ts.end());
  int ms = 0;
  int m0 = -1;
  int m1 = -1;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < total; i++) {
    dp[i][0][1] = -1;
    for (int j = 1; j <= ts.size(); j++) {
      dp[i][j][1] = -1;
      if (dp[i][j - 1][0] > dp[i][j][0]) {
        dp[i][j][0] = dp[i][j - 1][0];
        dp[i][j][1] = i;
        dp[i][j][2] = j - 1;
      }
      array<int, 4> t = ts[j - 1];
      if (i - t[1] < 0 || t[0] < i) continue;
      if (dp[i - t[1]][j - 1][0] + t[2] > dp[i][j][0]) {
        dp[i][j][0] = dp[i - t[1]][j - 1][0] + t[2];
        dp[i][j][1] = i - t[1];
        dp[i][j][2] = j - 1;
      }
      if (dp[i][j][0] > ms) {
        ms = dp[i][j][0];
        m0 = i;
        m1 = j;
      }
    }
  }
  printf("%d\n", ms);
  if (ms == 0) {
    puts("0");
    return 0;
  }
  int cur0 = m0;
  int cur1 = m1;
  vector<array<int, 3> > ret;
  while (dp[cur0][cur1][0]) {
    while (dp[cur0][cur1][1] == cur0) {
      cur1 = dp[cur0][cur1][2];
    }
    ret.push_back({{ts[cur1 - 1][3], dp[cur0][cur1][1] + 1, cur0}});
    int t0, t1;
    t0 = dp[cur0][cur1][1];
    t1 = dp[cur0][cur1][2];
    cur0 = t0;
    cur1 = t1;
  }
  reverse(ret.begin(), ret.end());
  printf("%d\n", (int)ret.size());
  for (auto v : ret) {
    printf("%d %s %s\n", v[0], ToTime(v[1]).c_str(), ToTime(v[2]).c_str());
  }
  return 0;
}
