#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50050 + 1;
const int MAXM = 110 + 1;
const int MAXL = 64 + 1;
map<string, int> courseMap;
int n, m, k, cost[MAXM], cnt[MAXN], T[MAXN];
bool tag[MAXN];
class Employer {
 public:
  int T, value, end, idx;
  inline bool init(int idx) {
    this->idx = idx;
    char tmpstr[MAXL];
    int d, h, m;
    scanf("%s%d%d:%d%d", tmpstr, &d, &h, &m, &value);
    map<string, int>::iterator iter = courseMap.find(tmpstr);
    if (iter == courseMap.end()) return false;
    T = cost[iter->second];
    end = cnt[((d - 1) * 24 + h) * 60 + m];
    return true;
  }
  inline bool operator<(const Employer& other) const {
    return end < other.end || (end == other.end && T > other.T);
  }
};
vector<Employer> employer;
vector<pair<int, int> > output;
int dp[MAXN][MAXM], path[MAXN][MAXM];
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    char tmpstr[MAXL];
    scanf("%s", tmpstr);
    int size = (int)courseMap.size();
    courseMap[tmpstr] = size;
  }
  for (int i = 0; i < n; i++) scanf("%d", &cost[i]);
  for (int o = 0; o < 4; o++) {
    int x1, y1, x2, y2, t1, t2;
    scanf("%d:%d-%d:%d", &x1, &y1, &x2, &y2);
    t1 = x1 * 60 + y1;
    t2 = x2 * 60 + y2;
    assert(t1 <= t2);
    for (int i = 0; i < k; i++) {
      for (int j = t1, k = i * 60 * 24 + t1; j <= t2; j++, k++) {
        tag[k] = true;
        cnt[k] = 1;
      }
    }
  }
  int N = -1;
  for (int o = 0; o < k; o++) {
    int s = o * 60 * 24, t = s + 60 * 24;
    for (int i = s; i < t; i++) {
      if (!tag[i]) T[++N] = i;
      cnt[i] += N;
    }
  }
  N++;
  for (int i = 0; i < m; i++) {
    Employer em;
    if (em.init(i + 1)) employer.push_back(em);
  }
  sort(employer.begin(), employer.end());
  m = (int)employer.size();
  if (N == -1 || !m) {
    puts("0\n0");
    return 0;
  }
  for (int i = N; i >= 0; i--) {
    for (int j = 0; j <= m; j++) dp[i][j] = -1;
  }
  int res = -1, pos = -1;
  dp[0][0] = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < m; j++) {
      if (dp[i][j] == -1) continue;
      if (dp[i][j + 1] < dp[i][j]) {
        dp[i][j + 1] = dp[i][j];
        path[i][j + 1] = i;
      }
      int ii = i + employer[j].T;
      if (ii <= employer[j].end &&
          dp[ii][j + 1] < dp[i][j] + employer[j].value) {
        dp[ii][j + 1] = dp[i][j] + employer[j].value;
        path[ii][j + 1] = i;
      }
    }
    if (res < dp[i][m]) {
      res = dp[i][m];
      pos = i;
    }
  }
  for (int i = m; i > 0; i--) {
    if (path[pos][i] == pos) continue;
    output.push_back(make_pair(path[pos][i], i - 1));
    pos = path[pos][i];
  }
  printf("%d\n%d\n", res, (int)output.size());
  for (int i = (int)output.size() - 1; i >= 0; i--) {
    int s = output[i].first, idx = output[i].second,
        e = s + employer[idx].T - 1;
    s = T[s];
    e = T[e];
    printf("%d %d %02d:%02d %d %02d:%02d\n", employer[idx].idx, s / 60 / 24 + 1,
           s / 60 % 24, s % 60, e / 60 / 24 + 1, e / 60 % 24, e % 60);
  }
  return 0;
}
