#include <bits/stdc++.h>
using namespace std;
map<string, int> T;
string s[100], word;
int get_time(string s) {
  return (s[0] - '0') * 600 + (s[1] - '0') * 60 + (s[3] - '0') * 10 +
         (s[4] - '0');
}
int n, m, d, i, j, breaks[4][2], dp[101][30 * 24 * 60 + 1], total_break,
    day_work[24 * 60 + 5];
vector<pair<pair<int, int>, pair<int, int> > > V;
vector<int> V1, V2, V3;
int rec(int at, int worked) {
  if (at == n) {
    return 0;
  }
  int& ret = dp[at][worked];
  if (ret != -1) return ret;
  ret = rec(at + 1, worked);
  if (worked + V[at].second.first <= V[at].first.first)
    ret = max(ret,
              V[at].second.second + rec(at + 1, worked + V[at].second.first));
  return ret;
}
void solve(int at, int worked, int money) {
  if (money == 0) return;
  if (money == rec(at + 1, worked))
    solve(at + 1, worked, money);
  else {
    V1.push_back(V[at].first.second);
    V2.push_back(worked);
    V3.push_back(worked + V[at].second.first);
    solve(at + 1, worked + V[at].second.first, money - V[at].second.second);
  }
}
void print_time1(int t) {
  cout << " " << (t - 1) / (24 * 60 - total_break) + 1;
  t = (t - 1) % (24 * 60 - total_break) + 1;
  int i = 0;
  while (day_work[i] != t) i++;
  i--;
  printf(" %02d:%02d", i / 60, i % 60);
}
void print_time2(int t) {
  cout << " " << t / (24 * 60 - total_break) + 1;
  t %= (24 * 60 - total_break);
  int i = 0;
  while (day_work[i] != t) i++;
  while (i <= 24 * 60 && day_work[i] == t) i++;
  i--;
  printf(" %02d:%02d", i / 60, i % 60);
}
int main() {
  cin >> m >> n >> d;
  for (i = 0; i < m; i++) {
    cin >> s[i];
  }
  for (i = 0; i < m; i++) {
    cin >> j;
    T[s[i]] = j;
  }
  for (i = 0; i < 4; i++) {
    cin >> word;
    breaks[i][0] = get_time(word.substr(0, 5));
    breaks[i][1] = get_time(word.substr(6)) + 1;
    total_break += (breaks[i][1] - breaks[i][0]);
  }
  for (i = 0; i <= 24 * 60; i++) {
    day_work[i] = i;
    for (j = 0; j < 4; j++) {
      if (breaks[j][1] <= i)
        day_work[i] -= (breaks[j][1] - breaks[j][0]);
      else if (breaks[j][0] <= i)
        day_work[i] -= (i - breaks[j][0]);
    }
  }
  for (i = 0; i < n; i++) {
    int _c, _d, _t, _ddln, _until;
    string _word;
    cin >> word >> _d >> _word >> _c;
    _d--;
    _ddln = get_time(_word);
    _until = (24 * 60 - total_break) * _d + day_work[_ddln];
    _ddln += _d * 24 * 60;
    if (T.count(word)) {
      _t = T[word];
      V.push_back(make_pair(make_pair(_until, i + 1), make_pair(_t, _c)));
    }
  }
  n = V.size();
  sort(V.begin(), V.end());
  memset(dp, -1, sizeof(dp));
  int ans = rec(0, 0);
  cout << ans << endl;
  solve(0, 0, ans);
  cout << V1.size() << endl;
  for (i = 0; i < V1.size(); i++) {
    cout << V1[i];
    print_time2(V2[i]);
    print_time1(V3[i]);
    cout << endl;
  }
  return 0;
}
